From 7cc750e6164c8bf323f62269279e1833a3d06e7d Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 20 Sep 2012 18:28:29 +0000 Subject: [PATCH] - cancel_jobs tool: add --name option to cancel job by name. From David Coss. svn path=/trunk/boinc/; revision=26132 --- checkin_notes | 8 ++++++++ tools/backend_lib.cpp | 30 ++++++++++++++++++++++++++++++ tools/backend_lib.h | 4 ++++ tools/cancel_jobs.cpp | 29 +++++++++++++++++++++-------- 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/checkin_notes b/checkin_notes index 23ee235dec..82665733e0 100644 --- a/checkin_notes +++ b/checkin_notes @@ -6007,3 +6007,11 @@ David 20 Sept 2012 MainDocument.cpp client/ makefile_sim + +David 20 Sept 2012 + - cancel_jobs tool: add --name option to cancel job by name. + From David Coss. + + tools/ + backend_lib.cpp,h + cancel_jobs.cpp diff --git a/tools/backend_lib.cpp b/tools/backend_lib.cpp index 4f79c48021..fa0073b7a6 100644 --- a/tools/backend_lib.cpp +++ b/tools/backend_lib.cpp @@ -517,6 +517,8 @@ int create_delete_file_msg(int host_id, const char* file_name) { return 0; } +// cancel jobs in a range of workunit IDs +// int cancel_jobs(int min_id, int max_id) { DB_WORKUNIT wu; DB_RESULT result; @@ -541,4 +543,32 @@ int cancel_jobs(int min_id, int max_id) { return 0; } +// cancel a particular job +// +int cancel_job(DB_WORKUNIT& wu) { + DB_RESULT result; + char set_clause[256], where_clause[256]; + int retval; + + // cancel unsent results + // + sprintf(set_clause, "server_state=%d, outcome=%d", + RESULT_SERVER_STATE_OVER, RESULT_OUTCOME_DIDNT_NEED + ); + sprintf(where_clause, "server_state=%d and workunitid=%d", + RESULT_SERVER_STATE_UNSENT, wu.id + ); + retval = result.update_fields_noid(set_clause, where_clause); + if (retval) return retval; + + // cancel the workunit + // + sprintf(set_clause, "error_mask=error_mask|%d, transition_time=%d", + WU_ERROR_CANCELLED, (int)(time(0)) + ); + retval = wu.update_field(set_clause); + if (retval) return retval; + return 0; +} + const char *BOINC_RCSID_b5f8b10eb5 = "$Id$"; diff --git a/tools/backend_lib.h b/tools/backend_lib.h index c223956a8b..edb4480549 100644 --- a/tools/backend_lib.h +++ b/tools/backend_lib.h @@ -121,4 +121,8 @@ extern int create_delete_file_msg( // extern int cancel_jobs(int min_id, int max_id); +// cancel a particular job +// +extern int cancel_job(DB_WORKUNIT&); + #endif diff --git a/tools/cancel_jobs.cpp b/tools/cancel_jobs.cpp index c2e1588c70..fe401df7f4 100644 --- a/tools/cancel_jobs.cpp +++ b/tools/cancel_jobs.cpp @@ -16,8 +16,9 @@ // along with BOINC. If not, see . // cancel_jobs min-ID max-ID -// -// cancel jobs from min-ID to max-ID inclusive +// cancel jobs from min-ID to max-ID inclusive +// cancel_jobs --name wuname +// cancel the job with the given name #include @@ -26,14 +27,12 @@ void usage() { fprintf(stderr, "Usage: cancel_jobs min-ID max-ID\n"); + fprintf(stderr, "or cancel_jobs --name wuname\n"); exit(1); } int main(int argc, char** argv) { if (argc != 3) usage(); - int min_id = atoi(argv[1]); - int max_id = atoi(argv[2]); - if (!min_id || !max_id) usage(); int retval = config.parse_file(); if (retval) exit(1); @@ -45,10 +44,24 @@ int main(int argc, char** argv) { printf("boinc_db.open: %s\n", boincerror(retval)); exit(1); } - - retval = cancel_jobs(min_id, max_id); + if (!strcmp(argv[1], "--name")) { + DB_WORKUNIT wu; + char buf[256]; + sprintf(buf, "where name='%s'", argv[2]); + retval = wu.lookup(buf); + if (retval) { + fprintf(stderr, "No workunit named '%s'\n", argv[2]); + exit(1); + } + retval = cancel_job(wu); + } else { + int min_id = atoi(argv[1]); + int max_id = atoi(argv[2]); + if (!min_id || !max_id) usage(); + retval = cancel_jobs(min_id, max_id); + } if (retval) { - fprintf(stderr, "cancel_jobs() failed: %s\n", boincerror(retval)); + fprintf(stderr, "cancel job failed: %s\n", boincerror(retval)); exit(retval); } }