Is it possible to set priorities for jobs which having same run times under single scheduler?

154 views
Skip to first unread message

Sagar Hande

unread,
Mar 22, 2022, 9:41:56 AM3/22/22
to APScheduler
##############################################
def job1():
      print('performed job1') 
def job2(): 
       print('performed job2')
def job3(): 
       print('performed job3')

sched = BackgroundScheduler()
sched.add_job(job1,'interval', minutes=1) 
sched.add_job(job2, 'interval',minutes=1)
sched.add_job(job3, 'interval',minutes=1)
try:
         sched.start()
  except (KeyboardInterrupt, SystemExit): 
         pass
################################################
 
Need to give high priority to  job2

Alex Grönholm

unread,
Mar 23, 2022, 5:12:39 AM3/23/22
to apsch...@googlegroups.com

There is no such option. How would that work anyway?

--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/99c9b0de-107b-49a9-830f-f6b25a8de46cn%40googlegroups.com.

Sagar Hande

unread,
Mar 23, 2022, 8:07:47 AM3/23/22
to APScheduler
Hey Alex, 
Thanks for your reply.

Currently all jobs triggering randomly, even though I added 8 jobs serially . 
# Below is order of execution of jobs

performed  job2...
preformed  job1...
performed  job3...
performed  job5...
performed  job4...
performed  job8...
performed  job7...
performed  job6...

I was wondering , if there is any option like below
 add_job(func=job8,   priority=1 ,  trigger='interval', minutes=1) 
add_job(func=job7,   priority=2 ,  trigger='interval', minutes=1)  ...

so that  we can execute jobs by priorities when multiple jobs have same runtime.
I guess for now I need to handle priorities manually.

Alex Grönholm

unread,
Mar 23, 2022, 8:09:47 AM3/23/22
to apsch...@googlegroups.com

They are launched concurrently, assuming you have enough worker threads in the pool. That's why I said I don't understand what effect priority would have.

Sagar Hande

unread,
Mar 23, 2022, 8:55:54 AM3/23/22
to APScheduler
My use-case is :   
take backup of database daily, weekly, monthly etc.  let say we scheduled  jobs as below

daily_job(priority - 3,    backup_type=''partial),    weekly_job(priority-2,   backup_type=''partial)     & monthly_job(priority-1,   backup_type=''full)

with same runtime they will collide at some point.
In that case only  highest priority job i.e. monthly_job should be run and should take full backup instead partial.

I was thinking if we can run job by priority and lock Database so others would not take redundant backup.

Rishabh Gupta

unread,
May 10, 2023, 1:44:25 PM5/10/23
to APScheduler
One way can be to set max_workers to 1 so that only one function can run at a time. Add slight delay to your less prior jobs. Keep the delay very small, so that if one backup is running, the other backup will be scheduled, but since one is already running, it will be misfired.  Not sure if it will work, but you can try it.
Reply all
Reply to author
Forward
0 new messages