// Send this host any broadcast jobs. // Return true iff we sent anything // bool send_broadcast_jobs() { DB_RESULT result; int retval; char buf[256]; bool sent_something = false; for (int i=0; i<ssp->nassignments; i++) { ASSIGNMENT& asg = ssp->assignments[i]; if (config.debug_assignment) { log_messages.printf(MSG_NORMAL, "[assign] processing broadcast type %d\n", asg.target_type ); } // see if this assignment applies to this host // switch (asg.target_type) { case ASSIGN_NONE: sprintf(buf, "where hostid=%lu and workunitid=%lu", g_reply->host.id, asg.workunitid ); retval = result.lookup(buf); if (retval == ERR_DB_NOT_FOUND) { retval = send_assigned_job(asg); if (!retval) sent_something = true; } break; case ASSIGN_USER: if (g_reply->user.id != asg.target_id) continue; sprintf(buf, "where workunitid=%lu and hostid=%lu", asg.workunitid, g_reply->host.id ); retval = result.lookup(buf); if (retval == ERR_DB_NOT_FOUND) { retval = send_assigned_job(asg); if (!retval) sent_something = true; } break; case ASSIGN_TEAM: if (g_reply->team.id != asg.target_id) continue; sprintf(buf, "where workunitid=%lu and hostid=%lu", asg.workunitid, g_reply->host.id ); retval = result.lookup(buf); if (retval == ERR_DB_NOT_FOUND) { retval = send_assigned_job(asg); if (!retval) sent_something = true; } break; } } return sent_something; }
// send non-multi assigned jobs // bool send_assigned_jobs() { DB_ASSIGNMENT asg; DB_RESULT result; DB_WORKUNIT wu; bool sent_something = false; int retval; // for now, only look for user assignments // char buf[256]; sprintf(buf, "where target_type=%d and target_id=%d and multi=0", ASSIGN_USER, g_reply->user.id ); while (!asg.enumerate(buf)) { if (!work_needed(false)) continue; // if the WU doesn't exist, delete the assignment record. // retval = wu.lookup_id(asg.workunitid); if (retval) { asg.delete_from_db(); continue; } // don't send if WU is validation pending or completed, // or has transition pending // if (wu.need_validate) continue; if (wu.canonical_resultid) continue; if (wu.transition_time < time(0)) continue; // don't send if we already sent one to this host // sprintf(buf, "where workunitid=%d and hostid=%d", asg.workunitid, g_request->host.id ); retval = result.lookup(buf); if (retval != ERR_DB_NOT_FOUND) continue; // don't send if there's already one in progress to this user // sprintf(buf, "where workunitid=%d and userid=%d and server_state=%d", asg.workunitid, g_reply->user.id, RESULT_SERVER_STATE_IN_PROGRESS ); retval = result.lookup(buf); if (retval != ERR_DB_NOT_FOUND) continue; // OK, send the job // retval = send_assigned_job(asg); if (retval) continue; sent_something = true; // update the WU's transition time to time out this job // retval = wu.lookup_id(asg.workunitid); if (retval) continue; int new_tt = time(0) + wu.delay_bound; if (new_tt < wu.transition_time) { char buf2[256]; sprintf(buf2, "transition_time=%d", new_tt); wu.update_field(buf2); } } return sent_something; }
// Send targeted jobs of a given type. // NOTE: there may be an atomicity problem in the following. // Ideally it should be in a transaction. // bool send_jobs(int assign_type) { DB_ASSIGNMENT asg; DB_RESULT result; DB_WORKUNIT wu; int retval; bool sent_something = false; char query[256]; switch (assign_type) { case ASSIGN_USER: sprintf(query, "where target_type=%d and target_id=%lu and multi=0", ASSIGN_USER, g_reply->user.id ); break; case ASSIGN_HOST: sprintf(query, "where target_type=%d and target_id=%lu and multi=0", ASSIGN_HOST, g_reply->host.id ); break; case ASSIGN_TEAM: sprintf(query, "where target_type=%d and target_id=%lu and multi=0", ASSIGN_TEAM, g_reply->team.id ); break; } while (!asg.enumerate(query)) { if (!work_needed(false)) { asg.end_enumerate(); break; } // if the WU doesn't exist, delete the assignment record. // retval = wu.lookup_id(asg.workunitid); if (retval) { asg.delete_from_db(); continue; } if (!need_targeted_instance(wu, g_reply->host.id)) { continue; } // OK, send the job // if (config.debug_send) { log_messages.printf(MSG_NORMAL, "sending targeted job: %s\n", wu.name ); } retval = send_assigned_job(asg); if (retval) { log_messages.printf(MSG_NORMAL, "failed to send targeted job: %s\n", boincerror(retval) ); continue; } sent_something = true; // update the WU's transition time to time out this job // retval = wu.lookup_id(asg.workunitid); if (retval) continue; int new_tt = time(0) + wu.delay_bound; if (new_tt < wu.transition_time) { char buf2[256]; sprintf(buf2, "transition_time=%d", new_tt); wu.update_field(buf2); } } return sent_something; }