![]() #check crontab job and put crontab job to queue python manage. #create crontab job python manage.py rq_crontab_job Use_local_timezone=False # Interpret hours in the local timezone Queue_name='crontab_job', # In which queue the job should be put in Repeat=None, # Repeat this number of times (None means repeat forever) Kwargs=, # Keyword arguments passed into function when executed Scheduler = django_rq.get_scheduler('crontab_job') You should use django command to run schedule job Įnter image description here class Command(BaseCommand): Schedule_once(tasks.some_task_b, interval=120)Īlso I've wrapped this snippet to avoid imports at the package level: def init_scheduler(): Schedule_once(tasks.some_task_a, interval=60*5) Scheduler.schedule(now datetime.timedelta(seconds=interval), func, Map(scheduler.cancel, filter(lambda x: x.func=func, jobs)) # clear all scheduled jobs for this function For example, we’ll create a module logtotmp. ![]() If not func in functions or not interval in functions\ You can use the rq-scheduler to execute specific code at a specific time by creating a Scheduler object and passing it a function to execute, a Python datetime, and any arguments you want to pass to the function. Schedule job once or reschedule when interval changes Map(lambda x: functions.append(x.meta.get('interval')), jobs) Scheduler = django_rq.get_scheduler('default') you may need additional checking for a job arguments).Ĭode that works for me and fit my needs: import django_rq Scheduling strategy may be dependent of your specific needs (i.e. What you can do is write code yourself to schedule jobs. I've added scheduling to a _init_ module in one of my project application (in terms of Django), but wrapped with small function which prevents queueing jobs twice or more. Regarding rq-scheduler, I have no hands on experience with it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |