]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #8571 About adding intermediate JobStatus for Runscripts
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Mon, 24 Jan 2022 21:57:02 +0000 (22:57 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:57 +0000 (13:56 +0200)
bacula/src/dird/ua_status.c
bacula/src/jcr.h
bacula/src/lib/jcr.c
bacula/src/lib/runscript.c
bacula/src/stored/dircmd.c

index 08c23807df42e94fc40dd53078a5a939884add96..fc6017d709c65ed358f21bfdd8058f89ae1dc695 100644 (file)
@@ -1221,6 +1221,7 @@ static void list_running_jobs(UAContext *ua)
    bool pool_mem = false;
    OutputWriter ow(ua->api_opts);
    JobId_t jid = 0;
+   POOL_MEM msg_buf;
 
    if ((i = find_arg_with_value(ua, "jobid")) >= 0) {
       jid = str_to_int64(ua->argv[i]);
@@ -1443,10 +1444,18 @@ static void list_running_jobs(UAContext *ua)
          break;
       }
 
+      uint32_t curr_op = jcr->job_task;
+      if (curr_op != 0) {
+         /* We can add some more descriptive message */
+         Mmsg(msg_buf, "%s (%s)", msg, get_job_task(curr_op));
+      } else {
+         pm_strcpy(msg_buf, msg);
+      }
+
       if (ua->api == 1) {
          bash_spaces(jcr->comment);
          ua->send_msg(_("%6d\t%-6s\t%-20s\t%s\t%s\n"),
-                      jcr->JobId, level, jcr->Job, msg, jcr->comment);
+                      jcr->JobId, level, jcr->Job, msg_buf.c_str(), jcr->comment);
          unbash_spaces(jcr->comment);
 
       } else if (ua->api > 1) {
@@ -1460,7 +1469,7 @@ static void list_running_jobs(UAContext *ua)
                        OT_JOBLEVEL,"level",     jcr->getJobLevel(),
                        OT_JOBTYPE, "type",      jcr->getJobType(),
                        OT_JOBSTATUS,"status",   status,
-                       OT_STRING,  "status_desc",msg,
+                       OT_STRING,  "status_desc",msg_buf.c_str(),
                        OT_STRING,  "comment",   jcr->comment,
                        OT_SIZE,    "jobbytes",  jcr->JobBytes,
                        OT_INT32,   "jobfiles",  jcr->JobFiles,
@@ -1486,7 +1495,7 @@ static void list_running_jobs(UAContext *ua)
             jcr->JobId, b1, level,
             edit_uint64_with_commas(jcr->JobFiles, b2),
             edit_uint64_with_suffix(jcr->JobBytes, b3),
-            jcr->job->name(), msg);
+            jcr->job->name(), msg_buf.c_str());
       }
 
       if (pool_mem) {
index 50ab23a3f3474c97851e8fe8e5bbe4a39425baca..07bc3d87ea4c4bf47dfe70af825e39da31e9aa88 100644 (file)
 #define JS_CloudUpload           'u'  /* Cloud upload */
 #define JS_CloudDownload         'w'  /* Cloud download */
 
+/* Helper for more descriptive job status */
+enum {
+   JOB_TASK_ZERO = 0,
+   JOB_TASK_BEFORE_SCRIPT = 100,
+   JOB_TASK_AFTER_SCRIPT
+};
+
+struct job_task {
+   const uint32_t op_code;
+   const char *op_message;
+};
+
+
+const char *get_job_task(uint32_t op_code);
+
+
 /* Migration selection types. Do not change the order. */
 enum {
    MT_SMALLEST_VOL = 1,
@@ -258,7 +274,10 @@ public:
    char Job[MAX_NAME_LENGTH];         /* Unique name of this Job */
    char event[MAX_NAME_LENGTH];       /* Current event (python) */
    uint32_t eventType;                /* Current event type (plugin) */
-
+   uint32_t job_task;                 /* Used to add description of current opearion being executed
+                                         (e.g. 'running AfterJob script').
+                                         If not 0, it can be used to make current job
+                                         status more descriptive. */
    uint32_t JobId;                    /* Director's JobId */
    uint32_t VolSessionId;
    uint32_t VolSessionTime;
index 16be87520927ffc6fb9ec08b2a44d96fb19e6d7e..b58957088a85c10d9138433b64a7c274fe42a1b8 100644 (file)
@@ -80,6 +80,15 @@ pthread_once_t key_once = PTHREAD_ONCE_INIT;
 
 static char Job_status[] = "Status JobId=%ld JobStatus=%d\n";
 
+/* Mapping of operation code to operation description */
+const struct job_task job_task_map[] = {
+   { JOB_TASK_ZERO, "\0" },
+   { JOB_TASK_BEFORE_SCRIPT, "executing Before Job Scripts" },
+   { JOB_TASK_AFTER_SCRIPT, "executing After Job Scripts" }
+};
+
+const uint32_t job_task_map_size = sizeof(job_task_map) / sizeof(job_task);
+
 void lock_jobs()
 {
    P(job_start_mutex);
@@ -395,6 +404,7 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
    jcr->setJobType(JT_SYSTEM);           /* internal job until defined */
    jcr->setJobLevel(L_NONE);
    jcr->setJobStatus(JS_Created);        /* ready to run */
+   jcr->job_task = JOB_TASK_ZERO;
 #ifndef HAVE_WIN32
    struct sigaction sigtimer;
    sigtimer.sa_flags = 0;
@@ -1210,6 +1220,18 @@ int get_next_jobid_from_list(char **p, uint32_t *JobId)
    return 1;
 }
 
+/* Get description of operation by given job task code */
+const char *get_job_task(uint32_t op_code)
+{
+   for (uint32_t i=0; i<job_task_map_size; i++) {
+      if (job_task_map[i].op_code == op_code) {
+         return job_task_map[i].op_message;
+      }
+   }
+
+   return NULL;
+}
+
 /*
  * Timeout signal comes here
  */
index c43b312a33ffc7c31806283a508ba2944d2d5075..d8583f825ddf0c9f2483cacec7635e10851387cb 100644 (file)
@@ -130,6 +130,8 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label)
             Dmsg4(200, "runscript: Run it because SCRIPT_Before (%s,%i,%i,%c)\n",
                   script->command, script->on_success, script->on_failure,
                   jcr->JobStatus );
+            /* Set job task code */
+            jcr->job_task = JOB_TASK_BEFORE_SCRIPT;
             runit = true;
          }
       }
@@ -142,6 +144,8 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label)
             Dmsg4(200, "runscript: Run it because SCRIPT_AfterVSS (%s,%i,%i,%c)\n",
                   script->command, script->on_success, script->on_failure,
                   jcr->JobStatus );
+            /* Set job task code */
+            jcr->job_task = JOB_TASK_AFTER_SCRIPT;
             runit = true;
          }
       }
@@ -156,6 +160,8 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label)
             Dmsg4(200, "runscript: Run it because SCRIPT_After (%s,%i,%i,%c)\n",
                   script->command, script->on_success, script->on_failure,
                   jcr->JobStatus );
+            /* Set job task code */
+            jcr->job_task = JOB_TASK_AFTER_SCRIPT;
             runit = true;
          }
       }
@@ -172,6 +178,9 @@ int run_scripts(JCR *jcr, alist *runscripts, const char *label)
       }
    }
 
+   /* Script ended, reset operation code */
+   jcr->job_task = JOB_TASK_ZERO;
+
    return ret;
 }
 
index b548da82bb2e0fb0190d4015fe8aec4c1a6d2f9b..533c52e5d8d6811b756556975b214b53ba0c837c 100644 (file)
@@ -1004,7 +1004,6 @@ static void label_volume_if_ok(DCR *dcr, char *oldname,
    int mode;
    const char *volname = (relabel == 1) ? oldname : newname;
    uint64_t volCatBytes;
-   bool opened = false;
 
    if (!obtain_device_block(dev,
                             &hold,