I'm trying to implement django extension management job. I would like to know how could I fire the job inside django in order to run the code daily and specify exact time like 4:00 am in django extension management job. so far code given below:
from django_extensions.management.jobs import DailyJob
class Job(DailyJob):
help = "Send notification On Instruction Instances"
def execute(self):
print("job executed at 4:00 Am")
Any help will be highly appreciated
Django doesn't handle the timing, crontab does.
As long as you're ok with all daily jobs running at 4am you can just update your crontab to use that. The docs show:
And these docs show that
@dailyis equivalent to0 0 * * *.So just change your crontab to:
Their source code also shows there is a
runjobcommand which can take a job name. So to run just that job at 4am, you would use:However, this job must not be a DailyJob then, since it would run twice (once daily from
runjobs daily, once at 4am fromrunjob myjob). I think to do this, you would just inherit fromBaseJobinstead:But I am not 100% sure where this would go in your code. I'd probably start by trying to add it directly under the
jobs/directory.