- Dmsg1(100, "Calling user engine for jobid=%d\n", jcr->JobId);
- jq->engine(je->jcr);
- Dmsg1(100, "Back from user engine jobid=%d.\n", jcr->JobId);
- if ((stat = pthread_mutex_lock(&jq->mutex)) != 0) {
- jq->num_workers--;
- free(je); /* release job entry */
- return NULL;
- }
- Dmsg0(200, "Done lock mutex\n");
- jq->running_jobs->remove(je);
- /*
- * Release locks if acquired. Note, they will not have
- * been acquired for jobs canceled before they were
- * put into the ready queue.
- */
- if (jcr->acquired_resource_locks) {
- jcr->store->NumConcurrentJobs--;
- jcr->client->NumConcurrentJobs--;
- jcr->job->NumConcurrentJobs--;
- }
-
- if (jcr->job->RescheduleOnError &&
- jcr->JobStatus != JS_Terminated &&
- jcr->JobStatus != JS_Canceled &&
- jcr->job->RescheduleTimes > 0 &&
- jcr->reschedule_count < jcr->job->RescheduleTimes) {
-
- /*
- * Reschedule this job by cleaning it up, but
- * reuse the same JobId if possible.
- */
- jcr->reschedule_count++;
- jcr->sched_time = time(NULL) + jcr->job->RescheduleInterval;
- Dmsg2(100, "Rescheduled Job %s to re-run in %d seconds.\n", jcr->Job,
- (int)jcr->job->RescheduleInterval);
- jcr->JobStatus = JS_Created; /* force new status */
- dird_free_jcr(jcr); /* partial cleanup old stuff */
- if (jcr->JobBytes == 0) {
- Dmsg1(100, "Requeue job=%d\n", jcr->JobId);
- V(jq->mutex);
- jobq_add(jq, jcr); /* queue the job to run again */
- P(jq->mutex);
- free(je); /* free the job entry */
- continue; /* look for another job to run */
- }
- /*
- * Something was actually backed up, so we cannot reuse
- * the old JobId or there will be database record
- * conflicts. We now create a new job, copying the
- * appropriate fields.
- */
- JCR *njcr = new_jcr(sizeof(JCR), dird_free_jcr);
- set_jcr_defaults(njcr, jcr->job);
- njcr->reschedule_count = jcr->reschedule_count;
- njcr->JobLevel = jcr->JobLevel;
- njcr->JobStatus = jcr->JobStatus;
- njcr->pool = jcr->pool;
- njcr->store = jcr->store;
- njcr->messages = jcr->messages;
- Dmsg0(100, "Call to run new job\n");
- V(jq->mutex);
+ Dmsg2(2300, "Calling user engine for jobid=%d use=%d\n", jcr->JobId,
+ jcr->use_count());
+ jq->engine(je->jcr);
+
+ Dmsg2(2300, "Back from user engine jobid=%d use=%d.\n", jcr->JobId,
+ jcr->use_count());
+
+ /* Reacquire job queue lock */
+ P(jq->mutex);
+ Dmsg0(200, "Done lock mutex after running job. Release locks.\n");
+ jq->running_jobs->remove(je);
+ /*
+ * Release locks if acquired. Note, they will not have
+ * been acquired for jobs canceled before they were
+ * put into the ready queue.
+ */
+ if (jcr->acquired_resource_locks) {
+ if (jcr->rstore) {
+ jcr->rstore->NumConcurrentJobs = 0;
+ Dmsg1(200, "Dec rncj=%d\n", jcr->rstore->NumConcurrentJobs);
+ }
+ if (jcr->wstore) {
+ jcr->wstore->NumConcurrentJobs--;
+ Dmsg1(200, "Dec wncj=%d\n", jcr->wstore->NumConcurrentJobs);
+ }
+ jcr->client->NumConcurrentJobs--;
+ jcr->job->NumConcurrentJobs--;
+ jcr->acquired_resource_locks = false;
+ }
+
+ /*
+ * Reschedule the job if necessary and requested
+ */
+ if (jcr->job->RescheduleOnError &&
+ jcr->JobStatus != JS_Terminated &&
+ jcr->JobStatus != JS_Canceled &&
+ jcr->JobType == JT_BACKUP &&
+ (jcr->job->RescheduleTimes == 0 ||
+ jcr->reschedule_count < jcr->job->RescheduleTimes)) {
+ char dt[50], dt2[50];
+
+ /*
+ * Reschedule this job by cleaning it up, but
+ * reuse the same JobId if possible.
+ */
+ time_t now = time(NULL);
+ jcr->reschedule_count++;
+ jcr->sched_time = now + jcr->job->RescheduleInterval;
+ bstrftime(dt, sizeof(dt), now);
+ bstrftime(dt2, sizeof(dt2), jcr->sched_time);
+ Dmsg4(2300, "Rescheduled Job %s to re-run in %d seconds.(now=%u,then=%u)\n", jcr->Job,
+ (int)jcr->job->RescheduleInterval, now, jcr->sched_time);
+ Jmsg(jcr, M_INFO, 0, _("Rescheduled Job %s at %s to re-run in %d seconds (%s).\n"),
+ jcr->Job, dt, (int)jcr->job->RescheduleInterval, dt2);
+ dird_free_jcr_pointers(jcr); /* partial cleanup old stuff */
+ jcr->JobStatus = -1;
+ set_jcr_job_status(jcr, JS_WaitStartTime);
+ jcr->SDJobStatus = 0;
+ if (jcr->JobBytes == 0) {
+ Dmsg2(2300, "Requeue job=%d use=%d\n", jcr->JobId, jcr->use_count());
+ V(jq->mutex);
+ jobq_add(jq, jcr); /* queue the job to run again */
+ P(jq->mutex);
+ free_jcr(jcr); /* release jcr */
+ free(je); /* free the job entry */
+ continue; /* look for another job to run */
+ }
+ /*
+ * Something was actually backed up, so we cannot reuse
+ * the old JobId or there will be database record
+ * conflicts. We now create a new job, copying the
+ * appropriate fields.
+ */
+ JCR *njcr = new_jcr(sizeof(JCR), dird_free_jcr);
+ set_jcr_defaults(njcr, jcr->job);
+ njcr->reschedule_count = jcr->reschedule_count;
+ njcr->sched_time = jcr->sched_time;
+ njcr->JobLevel = jcr->JobLevel;
+ njcr->JobStatus = -1;
+ set_jcr_job_status(njcr, jcr->JobStatus);
+ if (jcr->rstore) {
+ copy_rstorage(njcr, jcr->rstorage, _("previous Job"));
+ } else {
+ free_rstorage(njcr);
+ }
+ if (jcr->wstore) {
+ copy_wstorage(njcr, jcr->wstorage, _("previous Job"));
+ } else {
+ free_wstorage(njcr);
+ }
+ njcr->messages = jcr->messages;
+ Dmsg0(2300, "Call to run new job\n");
+ V(jq->mutex);