You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use django-apscheduler with a runapscheduler.py manage.py command script, where I have a bunch of scheduled jobs defined that run periodically. All works perfectly fine.
Now I have a task that should only ever be executed manually, never periodically. The idea is that I add a button somewhere in the Django Admin that our marketing manager can press, which will then add a job to the queue, to be executed once, as soon as possible.
Can I use django-apscheduler to run one-off jobs like this?
I know there’s an example in the README of triggering a job via the DjangoJob admin page, but we don’t include this page in our admin site. I want to add a button somewhere else that should add this job to the queue.
Do I have to create my own DjangoMemoryJobStore and add the job to it without a trigger? Does the job already have to exist in my main runapscheduler.py scheduler? But how can I create a job there that never runs? How do I shutdown the scheduler when the single job completes?
Or rather than creating a separate BackgroundScheduler instance, can I not add this job to the already running BlockingScheduler, part of runapscheduler.py manage command?
Is there an example of executing one single piece of code in the background, one time? Can I even use django-apscheduler for this? I'd rather not add another background task runner into the mix just for this one use case 😬
The text was updated successfully, but these errors were encountered:
Or rather than creating a separate BackgroundScheduler instance, can I not add this job to the already running BlockingScheduler, part of runapscheduler.py manage command?
Ah, I guess this is not really possible due to what #155 also ran into. So then I do have to create a brand new scheduler and start it from within my view, and make sure it shuts down properly again when the job finishes. It seems quite complex just to run a single task?
And then you also have to contend with users clicking the same button multiple times (or multiple users in multiple browsers doing the same) without being able to force single-threaded execution.
Assuming the job can be run in less than 30 seconds it might be best to just run the logic in your view directly.
I thought that the button getting clicked multiple times wouldn't be a big problem since jobs have an ID and I can check if such a job is already in the queue.
But it's also not really a problem if the job does end up in the queue multiple times.
I use django-apscheduler with a
runapscheduler.py
manage.py command script, where I have a bunch of scheduled jobs defined that run periodically. All works perfectly fine.Now I have a task that should only ever be executed manually, never periodically. The idea is that I add a button somewhere in the Django Admin that our marketing manager can press, which will then add a job to the queue, to be executed once, as soon as possible.
Can I use django-apscheduler to run one-off jobs like this?
I know there’s an example in the README of triggering a job via the DjangoJob admin page, but we don’t include this page in our admin site. I want to add a button somewhere else that should add this job to the queue.
Do I have to create my own DjangoMemoryJobStore and add the job to it without a trigger? Does the job already have to exist in my main
runapscheduler.py
scheduler? But how can I create a job there that never runs? How do I shutdown the scheduler when the single job completes?Or rather than creating a separate
BackgroundScheduler
instance, can I not add this job to the already runningBlockingScheduler
, part ofrunapscheduler.py
manage command?Is there an example of executing one single piece of code in the background, one time? Can I even use django-apscheduler for this? I'd rather not add another background task runner into the mix just for this one use case 😬
The text was updated successfully, but these errors were encountered: