Dmsg0(100, "Enter admin_cleanup()\n");
+ /* Job needs to be marked as terminated before running the after runscript */
+ jcr->setJobStatus(TermCode);
+
+ run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+
+ /* Runscript could have changed JobStatus,
+ * now check if it should be changed in the report or not */
+ TermCode = compareJobStatus(TermCode, jcr->JobStatus);
+
update_job_end(jcr, TermCode);
if (!db_get_job_record(jcr, jcr->db, &jcr->jr)) {
msg_type = M_INFO; /* by default INFO message */
switch (jcr->JobStatus) {
case JS_Terminated:
- term_msg = _("Admin OK");
+ if (jcr->JobErrors) {
+ term_msg = _("Admin OK -- with warnings");
+ } else {
+ term_msg = _("Admin OK");
+ }
break;
case JS_FatalError:
case JS_ErrorTerminated:
Dmsg2(100, "Enter backup_cleanup %d %c\n", TermCode, TermCode);
memset(&cr, 0, sizeof(cr));
+ /* Job needs to be marked as terminated before running the after runscript */
+ jcr->setJobStatus(TermCode);
+
+ run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+
+ /* Runscript could have changed JobStatus,
+ * now check if it should be changed in the report or not */
+ TermCode = compareJobStatus(TermCode, jcr->JobStatus);
+
#ifdef xxxx
/* The current implementation of the JS_Warning status is not
* completed. SQL part looks to be ok, but the code is using
break;
}
- run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
-
/* Send off any queued messages */
if (jcr->msg_queue && jcr->msg_queue->size() > 0) {
dequeue_messages(jcr);
remove_dummy_jobmedia_records(jcr);
Dmsg2(100, "Enter mac_cleanup %d %c\n", TermCode, TermCode);
- update_job_end(jcr, TermCode);
+
+ /* Job needs to be marked as terminated before running the after runscript */
+ jcr->setJobStatus(TermCode);
/*
* Check if we actually did something.
db_sql_query(wjcr->db, query.c_str(), NULL, NULL);
}
}
+ run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+
+ /* Runscript could have changed JobStatus,
+ * now check if it should be changed in the report or not */
+ TermCode = compareJobStatus(TermCode, jcr->JobStatus);
+
+ update_job_end(jcr, TermCode);
switch (jcr->JobStatus) {
case JS_Terminated:
utime_t RunTime;
Dmsg0(20, "In restore_cleanup\n");
+
+ /* Job needs to be marked as terminated before running the after runscript */
+ jcr->setJobStatus(TermCode);
+
+ run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+
+ /* Runscript could have changed JobStatus,
+ * now check if it should be changed in the report or not */
+ TermCode = compareJobStatus(TermCode, jcr->JobStatus);
+
update_job_end(jcr, TermCode);
memset(&cr, 0, sizeof(cr));
Dmsg2(100, "Enter vbackup_cleanup %d %c\n", TermCode, TermCode);
memset(&cr, 0, sizeof(cr));
+ /* Job needs to be marked as terminated before running the after runscript */
+ jcr->setJobStatus(TermCode);
+
+ run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+
+ /* Runscript could have changed JobStatus,
+ * now check if it should be changed in the report or not */
+ TermCode = compareJobStatus(TermCode, jcr->JobStatus);
+
jcr->jr.JobLevel = L_FULL; /* we want this to appear as a Full backup */
jcr->JobFiles = jcr->SDJobFiles;
jcr->JobBytes = jcr->SDJobBytes;
TermCode = JS_ErrorTerminated;
}
+ /* Job needs to be marked as terminated before running the after runscript */
+ jcr->setJobStatus(TermCode);
+
+ run_scripts(jcr, jcr->job->RunScripts, "AfterJob");
+
+ /* Runscript could have changed JobStatus,
+ * now check if it should be changed in the report or not */
+ TermCode = compareJobStatus(TermCode, jcr->JobStatus);
+
update_job_end(jcr, TermCode);
if (job_canceled(jcr)) {
job_started_time = time(NULL);
}
-static pthread_mutex_t status_lock = PTHREAD_MUTEX_INITIALIZER;
-
-void JCR::setJobStatus(int newJobStatus)
+/*
+ * Compare two job statuses, return one with higher priority.
+ */
+int compareJobStatus(int oldJobStatus, int newJobStatus)
{
int priority, old_priority;
- int oldJobStatus = JobStatus;
+ int ret_status = oldJobStatus;
- P(status_lock);
priority = get_status_priority(newJobStatus);
old_priority = get_status_priority(oldJobStatus);
-
- Dmsg2(800, "set_jcr_job_status(%ld, %c)\n", JobId, newJobStatus);
-
- /* Update wait_time depending on newJobStatus and oldJobStatus */
- update_wait_time(this, newJobStatus);
-
/*
* For a set of errors, ... keep the current status
* so it isn't lost. For all others, set it.
priority == 0 && old_priority == 0)) {
Dmsg4(800, "Set new stat. old: %c,%d new: %c,%d\n",
(oldJobStatus==0)?'0':oldJobStatus, old_priority, newJobStatus, priority);
- JobStatus = newJobStatus; /* replace with new status */
+ ret_status = newJobStatus; /* replace with new status */
}
- if (oldJobStatus != JobStatus) {
+ if (oldJobStatus != newJobStatus) {
Dmsg2(800, "leave setJobStatus old=%c new=%c\n", (oldJobStatus==0)?'0':oldJobStatus, newJobStatus);
// generate_plugin_event(this, bEventStatusChange, NULL);
}
+
+ return ret_status;
+}
+
+static pthread_mutex_t status_lock = PTHREAD_MUTEX_INITIALIZER;
+
+void JCR::setJobStatus(int newJobStatus)
+{
+
+ P(status_lock);
+
+ Dmsg2(800, "set_jcr_job_status(%ld, %c)\n", JobId, newJobStatus);
+
+ /* Update wait_time depending on newJobStatus and oldJobStatus */
+ update_wait_time(this, newJobStatus);
+
+ JobStatus = compareJobStatus(JobStatus, newJobStatus);
+
V(status_lock);
}
void remove_jcr_from_tsd(JCR *jcr);
uint32_t get_jobid_from_tsd();
uint32_t get_jobid_from_tid(pthread_t tid);
+int compareJobStatus(int oldJobStatus, int newJobStatus);
/* lex.c */
RUNSCRIPT *script;
bool runit;
-
+ bool ret = true; /* Changed to false in case any of the scripts fails */
int when;
if (strstr(label, NT_("Before"))) {
/* we execute it */
if (runit) {
- script->run(jcr, label);
+ if (!script->run(jcr, label)) {
+ ret = false; /* return err in case any of the script commands failed */
+ }
}
}
- return 1;
+
+ return ret;
}
bool RUNSCRIPT::is_local()