Skip to content

Commit

Permalink
Fix MaxRunSchedTime to cancel Job in time.
Browse files Browse the repository at this point in the history
Modified the code so MaxRunSchedTime will use the new
initial_sched_time when checking to see if a job should be canceled.

We have a set of jobs that we want to definitely end at a known
time - Z hours after they've been initially scheduled - no matter what
state the job is in.

Patch by Thomas Lohman from bacula devel mailinglist.
  • Loading branch information
Marco van Wieringen committed May 5, 2013
1 parent 20ccfb1 commit 588563c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -104,6 +104,7 @@ Scott Bailey
Sergey Svishchev
Stefan Reddig
Thomas Glatthor
Thomas Lohman
Thorsten Enge
Tim Oberfoell
Tomas Cameron
Expand Down
2 changes: 1 addition & 1 deletion src/dird/job.c
Expand Up @@ -703,7 +703,7 @@ static bool job_check_maxrunschedtime(JCR *jcr)
if (jcr->MaxRunSchedTime == 0 || job_canceled(jcr)) {
return false;
}
if ((watchdog_time - jcr->sched_time) < jcr->MaxRunSchedTime) {
if ((watchdog_time - jcr->initial_sched_time) < jcr->MaxRunSchedTime) {
Dmsg3(200, "Job %p (%s) with MaxRunSchedTime %d not expired\n",
jcr, jcr->Job, jcr->MaxRunSchedTime);
return false;
Expand Down
1 change: 1 addition & 0 deletions src/dird/jobq.c
Expand Up @@ -675,6 +675,7 @@ static bool reschedule_job(JCR *jcr, jobq_t *jq, jobq_item_t *je)
set_jcr_defaults(njcr, jcr->res.job);
njcr->reschedule_count = jcr->reschedule_count;
njcr->sched_time = jcr->sched_time;
njcr->initial_sched_time = jcr->initial_sched_time;
/*
* Special test here since a Virtual Full gets marked
* as a Full, so we look at the resource record
Expand Down
3 changes: 2 additions & 1 deletion src/include/jcr.h
Expand Up @@ -314,6 +314,7 @@ class JCR {
volatile int32_t JobStatus; /* ready, running, blocked, terminated */
int32_t JobPriority; /* Job priority */
time_t sched_time; /* Job schedule time, i.e. when it should start */
time_t initial_sched_time; /* Original sched time before any reschedules are done */
time_t start_time; /* When job actually started */
time_t run_time; /* Used for computing speed */
time_t last_time; /* Last sample time */
Expand Down Expand Up @@ -398,7 +399,7 @@ class JCR {
uint32_t ExpectedFiles; /* Expected restore files */
uint32_t MediaId; /* DB record IDs associated with this job */
uint32_t FileIndex; /* Last FileIndex processed */
utime_t MaxRunSchedTime; /* Max run time in seconds from Scheduled time*/
utime_t MaxRunSchedTime; /* Max run time in seconds from Initial Scheduled time */
POOLMEM *fname; /* Name to put into catalog */
POOLMEM *component_fname; /* Component info file name */
FILE *component_fd; /* Component info file desc */
Expand Down
1 change: 1 addition & 0 deletions src/lib/jcr.c
Expand Up @@ -354,6 +354,7 @@ JCR *new_jcr(int size, JCR_free_HANDLER *daemon_free_jcr)
}
jcr->job_end_push.init(1, false);
jcr->sched_time = time(NULL);
jcr->initial_sched_time = jcr->sched_time;
jcr->daemon_free_jcr = daemon_free_jcr; /* plug daemon free routine */
jcr->init_mutex();
jcr->inc_use_count();
Expand Down

0 comments on commit 588563c

Please sign in to comment.