Skip to content

Commit 086b0c1

Browse files
rstalbowRyan Stalbow
andauthored
ISSUE-32 - Check job if job is active as well (#33)
Co-authored-by: Ryan Stalbow <[email protected]>
1 parent f5988dd commit 086b0c1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

scheduler/models/scheduled_job.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,18 @@ def callable_func(self):
8383
@admin.display(boolean=True, description=_('is scheduled?'))
8484
def is_scheduled(self) -> bool:
8585
"""Check whether job is queued/scheduled to be executed"""
86-
if not self.job_id:
86+
if not self.job_id: # no job_id => is not scheduled
8787
return False
88+
# check whether job_id is in scheduled/enqueued/active jobs
8889
scheduled_jobs = self.rqueue.scheduled_job_registry.get_job_ids()
8990
enqueued_jobs = self.rqueue.get_job_ids()
90-
res = (self.job_id in scheduled_jobs) or (self.job_id in enqueued_jobs)
91-
if not res: # self.job_id is not None
91+
active_jobs = self.rqueue.started_job_registry.get_job_ids()
92+
res = ((self.job_id in scheduled_jobs)
93+
or (self.job_id in enqueued_jobs)
94+
or (self.job_id in active_jobs))
95+
# If the job_id is not scheduled/enqueued/started,
96+
# update the job_id to None. (The job_id belongs to a previous run which is completed)
97+
if not res:
9298
self.job_id = None
9399
super(BaseJob, self).save()
94100
return res

0 commit comments

Comments
 (0)