int main() { if ( boinc_db.open("predictor", "boinc", NULL, NULL) ) { printf("Open failed\n"); return 0; } DB_WORKUNIT workunit; char buf[256]; while (!workunit.enumerate()) { printf("workunit %d wsn %d\n", workunit.id, workunit.workseq_next); DB_RESULT result; sprintf(buf, "where workunitid=%d", workunit.id); if ( !result.enumerate(buf) ) { DB_HOST host; sprintf(buf, "where id=%d", result.hostid); if ( !host.enumerate(buf) ) { workunit.workseq_next = OS(host) + CPU(host); if ( workunit.update() ) printf("Update failed!\n"); } } } };
int create_work( DB_WORKUNIT& wu, const char* _wu_template, const char* result_template_filename, const char* result_template_filepath, const char** infiles, int ninfiles, SCHED_CONFIG& config_loc, const char* command_line, const char* additional_xml ) { int retval; char _result_template[BLOB_SIZE]; char wu_template[BLOB_SIZE]; #if 0 retval = check_files(infiles, ninfiles, config_loc); if (retval) { fprintf(stderr, "Missing input file: %s\n", infiles[0]); return -1; } #endif strcpy(wu_template, _wu_template); wu.create_time = time(0); retval = process_input_template( wu, wu_template, infiles, ninfiles, config_loc, command_line, additional_xml ); if (retval) { fprintf(stderr, "process_input_template(): %d\n", retval); return retval; } retval = read_filename( result_template_filepath, _result_template, sizeof(_result_template) ); if (retval) { fprintf(stderr, "create_work: can't read result template file %s\n", result_template_filepath ); return retval; } if (strlen(result_template_filename) > sizeof(wu.result_template_file)-1) { fprintf(stderr, "result template filename is too big: %d bytes, max is %d\n", (int)strlen(result_template_filename), (int)sizeof(wu.result_template_file)-1 ); return ERR_BUFFER_OVERFLOW; } strlcpy(wu.result_template_file, result_template_filename, sizeof(wu.result_template_file)); if (wu.rsc_fpops_est == 0) { fprintf(stderr, "no rsc_fpops_est given; can't create job\n"); return ERR_NO_OPTION; } if (wu.rsc_fpops_bound == 0) { fprintf(stderr, "no rsc_fpops_bound given; can't create job\n"); return ERR_NO_OPTION; } if (wu.rsc_disk_bound == 0) { fprintf(stderr, "no rsc_disk_bound given; can't create job\n"); return ERR_NO_OPTION; } if (wu.target_nresults == 0) { fprintf(stderr, "no target_nresults given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_error_results == 0) { fprintf(stderr, "no max_error_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_total_results == 0) { fprintf(stderr, "no max_total_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_success_results == 0) { fprintf(stderr, "no max_success_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_success_results > wu.max_total_results) { fprintf(stderr, "max_success_results > max_total_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.max_error_results > wu.max_total_results) { fprintf(stderr, "max_error_results > max_total_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.target_nresults > wu.max_success_results) { fprintf(stderr, "target_nresults > max_success_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.transitioner_flags & TRANSITION_NONE) { wu.transition_time = INT_MAX; } else { wu.transition_time = time(0); } if (wu.id) { retval = wu.update(); if (retval) { fprintf(stderr, "create_work: workunit.update() %d\n", retval); return retval; } } else { retval = wu.insert(); if (retval) { fprintf(stderr, "create_work: workunit.insert() %d\n", retval); return retval; } wu.id = boinc_db.insert_id(); } return 0; }
// variant where input files are described by INFILE_DESCS, // so you can have remote files etc. // // If query_string is present, don't actually create the job; // instead, append to the query string. // The caller is responsible for doing the query. // int create_work2( DB_WORKUNIT& wu, const char* _wu_template, const char* result_template_filename, // relative to project root; stored in DB const char* /* result_template_filepath*/, // deprecated vector<INFILE_DESC> &infiles, SCHED_CONFIG& config_loc, const char* command_line, const char* additional_xml, char* query_string ) { int retval; char wu_template[BLOB_SIZE]; #if 0 retval = check_files(infiles, ninfiles, config_loc); if (retval) { fprintf(stderr, "Missing input file: %s\n", infiles[0]); return -1; } #endif safe_strcpy(wu_template, _wu_template); wu.create_time = time(0); retval = process_input_template( wu, wu_template, infiles, config_loc, command_line, additional_xml ); if (retval) { fprintf(stderr, "process_input_template(): %s\n", boincerror(retval)); return retval; } // check for presence of result template. // we don't need to actually look at it. // const char* p = config_loc.project_path(result_template_filename); if (!boinc_file_exists(p)) { fprintf(stderr, "create_work: result template file %s doesn't exist\n", p ); return retval; } if (strlen(result_template_filename) > sizeof(wu.result_template_file)-1) { fprintf(stderr, "result template filename is too big: %d bytes, max is %d\n", (int)strlen(result_template_filename), (int)sizeof(wu.result_template_file)-1 ); return ERR_BUFFER_OVERFLOW; } strlcpy(wu.result_template_file, result_template_filename, sizeof(wu.result_template_file)); if (wu.rsc_fpops_est == 0) { fprintf(stderr, "no rsc_fpops_est given; can't create job\n"); return ERR_NO_OPTION; } if (wu.rsc_fpops_bound == 0) { fprintf(stderr, "no rsc_fpops_bound given; can't create job\n"); return ERR_NO_OPTION; } if (wu.rsc_disk_bound == 0) { fprintf(stderr, "no rsc_disk_bound given; can't create job\n"); return ERR_NO_OPTION; } if (wu.target_nresults == 0) { fprintf(stderr, "no target_nresults given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_error_results == 0) { fprintf(stderr, "no max_error_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_total_results == 0) { fprintf(stderr, "no max_total_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_success_results == 0) { fprintf(stderr, "no max_success_results given; can't create job\n"); return ERR_NO_OPTION; } if (wu.max_success_results > wu.max_total_results) { fprintf(stderr, "max_success_results > max_total_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.max_error_results > wu.max_total_results) { fprintf(stderr, "max_error_results > max_total_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.target_nresults > wu.max_success_results) { fprintf(stderr, "target_nresults > max_success_results; can't create job\n"); return ERR_INVALID_PARAM; } if (wu.transitioner_flags) { wu.transition_time = INT_MAX; } else { wu.transition_time = time(0); } if (query_string) { wu.db_print_values(query_string); } else if (wu.id) { retval = wu.update(); if (retval) { fprintf(stderr, "create_work: workunit.update() %s\n", boincerror(retval) ); return retval; } } else { retval = wu.insert(); if (retval) { fprintf(stderr, "create_work: workunit.insert() %s\n", boincerror(retval) ); return retval; } wu.id = boinc_db.insert_id(); } return 0; }