Added the ability to unschedule jobs to the scheduler
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
from scheduler import scheduler
|
||||
from scheduler.exceptions import AlreadyScheduled
|
||||
|
||||
registered_jobs = {}
|
||||
|
||||
|
||||
def register_interval_job(func, weeks=0, days=0, hours=0, minutes=0,
|
||||
def register_interval_job(name, title, func, weeks=0, days=0, hours=0, minutes=0,
|
||||
seconds=0, start_date=None, args=None,
|
||||
kwargs=None, job_name=None, **options):
|
||||
|
||||
scheduler.add_interval_job(func=func, weeks=weeks, days=days,
|
||||
if name in registered_jobs:
|
||||
raise AlreadyScheduled
|
||||
|
||||
job = scheduler.add_interval_job(func=func, weeks=weeks, days=days,
|
||||
hours=hours, minutes=minutes, seconds=seconds,
|
||||
start_date=start_date, args=args, kwargs=kwargs)#, **options)
|
||||
start_date=start_date, args=args, kwargs=kwargs, **options)
|
||||
|
||||
registered_jobs[name] = {'title': title, 'job': job}
|
||||
|
||||
|
||||
def remove_job(name):
|
||||
if name in registered_jobs:
|
||||
scheduler.unschedule_job(registered_jobs[name]['job'])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user