New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need better documentation how to start Scheduler #51
Comments
You'll have to put in datetime in UTC. I do agree that the documentation could be very much improved. |
Server time is set to UTC so it is the same. How do I link/connect the Scheduler object and rqscheduler? Or asked differently how does rqscheduler know where to find the file containing Scheduler? |
Can the scheduler be stopped "safely"? |
Hi, @ui Thanks |
I'm absolutely swamped this week, will try to address your questions this weekend |
@selwin Hi Selwin, any chance you will have a moment soon? Thanks |
Sorry for the delay. When the scheduler is started, register_birth() is called and it sets the Similar to RQ, this library also intercepts At the moment, if
|
I would still be interested how to get rqscheduler process my jobs :-) |
Found a combination of the answers in this SO helpful: https://stackoverflow.com/questions/17537771/where-do-i-register-an-rq-scheduler-job-in-a-django-app/32033454#32033454 Short answer: You can put it in apps.py, eg.
|
@phoebebright I have similar configuration what you have suggested. But Mails are going repeatedly I have given 86400 interval i.e 24 hrs still Mails are going every second any help? |
@kevart Did you ever get this to work for you? Unfortunately, seems there's no one willing to explain how to get this to actually consume jobs as am getting |
In case someone needs an answer to @crazywizard254 comment, this can be caused by your method ( func ) not being included in INSTALLED_APPS. For example, you are trying to call a method in myapp.utils but myapp.utils is not specifically added to INSTALLED_APPS, you probably only have myapp in INSTALLED_APPS. |
Registering it in a Django AppConfig (or anywhere else in the standard Django import path) is problematic because of #121. I chose to build a custom management command for the scheduler and do the setup there. import datetime
import logging
import django_rq
from django_rq.management.commands import rqscheduler
scheduler = django_rq.get_scheduler()
log = logging.getLogger(__name__)
def clear_scheduled_jobs():
# Delete any existing jobs in the scheduler when the app starts up
for job in scheduler.get_jobs():
log.debug("Deleting scheduled job %s", job)
job.delete()
def register_scheduled_jobs():
# do your scheduling here
scheduler.schedule(...)
class Command(rqscheduler.Command):
def handle(self, *args, **kwargs):
# This is necessary to prevent dupes
clear_scheduled_jobs()
register_scheduled_jobs()
super(Command, self).handle(*args, **kwargs) |
@ipmb Thank you for that! Creating a management command solved all the issues I've been having trying to get this to function! |
If anyone is coming across this with the same problem, I originally thought @ipmb was saying I needed to run this management command in addition to the |
are we suppose to put this code in apps.py ? in our app. I'm using docker and there i'm running workers:
But the problem is function is not calling.
besides i'm using
but still nothing, function is never called. |
i was not running django scheduler worker in background. But now it working fine.
|
hmm I am still wrapping my head around this solution; how do you register the custom Command so 'python manage.py rqscheduler' picks it up? I tried to put 'import custom.Command' in init.py and that didn't work |
tried to import in apps/init.py or manage.py and got 'django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.'; |
@cyruszhang To use my solution, you'll need to create a custom management command: https://docs.djangoproject.com/en/dev/howto/custom-management-commands/ You would then run that command instead of |
Got it! thanks @ipmb |
can we schedule cron job with result_ttl scheduler.cron( cron_string, func = function_test, result_ttl = 0 ) |
Just leaving my comment here because I found this issue useful. Rather than overriding the scheduler command, I created a separate management command for destroying old scheduled jobs and creating new ones. The new command has almost identical logic to the overridden command class created by @ipmb The reason I separated it into another management command is because our system scales to multiple running instances of the same application, and each of them run an instance of With the separate management command that destroys and re-creates all scheduled jobs, I have more control over when (and how many times) that function runs. In my case, I include it in the "release" stage on Heroku, but this could apply to different stages of deployment, depending on what system you are using for application hosting. |
I put a simple task in a file (scheduler.py):
When launching rqscheduler it does nothing. The worker is running and executing jobs when executed from the django shell with log_info.delay().
I tried:
rqscheduler --host localhost --port 6379 --db 0
rqscheduler -H localhost -p 6379 -d 0 --path /home/foo/scheduler.py
rqscheduler -H localhost -p 6379 -d 0 --path /home/foo/
The text was updated successfully, but these errors were encountered: