Django celery executes method every other Friday? - cron

I'd like to have a method fire every other Friday using Django Celery. Unfortunately, I haven't been able to crack the crontab code.
Any thoughts?

Celery beat also lets you specify intervals instead of crontabs, you can set an interval of 14 days and start it running on a Friday.
It's not as precise as a crontab and you have to be careful if you restart the celery beat process i'm not sure if it restarts the timers or not.

You can find simple description here: http://docs.celeryproject.org/en/latest/userguide/periodic-tasks.html#crontab-schedules

Related

Calling a specific method on a certain time

I am currently working on a web application and I want to schedule a method that runs every day at 6 AM. Basically, if the clock ticks at 6 AM, this method will run. I have seen some answers on the Internet but none of these are scheduled at a fixed time of the day but rather timed after the app is ran.
I also have an alternative solution which is to check every minute if the time is 6 AM, and if so, I'll run the code. But is there other better answer than this?
Thank you!
On the server side, you could do it with a cron job.
On Linux follow these steps:
crontab -e
Here's an example of how to make a request to the google.com at 6AM (UTC)
# Each day at 6th hour (6 AM depending on your time zone settings, or UTC)
0 6 * * * curl -I http://google.com
:wq # save changes and quit
:q # to quit
:q! # to quit without saving changes
See more about Cron here. Or use a visual crontab entry creator if that is helpful. If you need a solution for Windows machine, you could also use a Windows scheduler to trigger events similar to cron.
Cron job would be a good way of doing it. However, for some reason if you can not schedule a cron job and need your own scheduler and your environment is Java based then you could use the Quartz Scheduler. It is a java based job scheduler like cron. It's usage is pretty simple.

Can I change Cron launch time when it's processing?

I'm new to Cron. I've just made a cron, which imports 8000 products. I've made it to import every hour, but I never want it to process again and to ensure, that it doesn't start again, when it's still goinf. Therefore, I want to change the time to like every week or something. Is this possible, even though the cron job is running?
Sorry for my bad formulation. I hope you understand.
Have a pleasant day.

Run cronjob for missing time periods

I Have crontab set up (on my local MacOSX system) to run a job on a per hourly basis. It runs fine. I am not sure if it is possible, but is there a way that I can run the job for 'missing' hours (in case my computer sleeps or I shut it down)?
For example if cronjob ran fine for hours (1-13) before I shut down the system. I start up the system again after, lets say 2 hours. Is there a way to tell cron to run the job for missing hours (14,15) too before executing hour 16?
The cronjob currently running fills up some data in my local MySQL DB with hour information in one of the columns. Any tips, tricks or libraries will be helpful.
Thanks.
Maybe have a look at anacron for Mac that can catch up jobs missed while your Mac was sleeping the next time it wakes up. See here.

Cron unexpected behaviour when date changes

I've a cron instance executing in a embedded device in a ELINOS4 environment. This device have a problem, I think related to battery, which changes the system date.
For the embedded application is not a problem because the app resynchornize the date. But for cron daemon affects its scheduler causing to programm next execution far in the future. Executing cron with flags I get this logs:
[3933] TargetTime=1359121500, sec-to-wait=60
...
[3933] spool dir mtime unch, no load needed.
[3933] tick(45,13,24,0,5) user [root:0:0:...] cmd="/etc/logrotate /etc/logrotate.conf"
[3933] TargetTime=1359121560, sec-to-wait=1130199663
[3933] sleeping for 1130199663 seconds
I've tried to change manually the date, but cron doesn't detect this change (it's sleeping https://stackoverflow.com/a/4141239).
One quick hack is to modify the source code of cron, but does a better solution exist?
Thanks in advance
Aside from the obvious "fix your hardware", the immediate suggestion would be to have a daemon that checks the time, and if it sees it jump back (or forward?) more than a few seconds, restart crond (and any other process that may use this sort of method to determine "next time to wake up").

cron jobs: Monitor time it takes for jobs to finish

I'm doing a research project that requires I monitor cron jobs on a Ubuntu Linux system. I have collected data about the jobs' tasks and when they are started, I just don't know of a way to monitor how long they take to finish running.
I could calculate the time of finishing the task minus starting it with something like this but that would require doing that on the Shell scripts of each cron job. That's not necessarily difficult by any means but it seems a little silly that cron wouldn't in some way log this, so I'm trying to find an easier way :P
tl;dr Figure out time cron jobs take from start to finish
You could just put time in front of your crontabs, and if you're getting notifications about cron script outputs, it'll get sent to you.
For example, if you had:
0 1,13 * * * /maint/run_webalizer.sh
add time in front
0 1,13 * * * time /maint/run_webalizer.sh
and you'll get some output that looks like (the "real" is the time you want):
real 3m1.255s
user 0m37.890s
sys 0m3.492s
If you don't get cron notifications, you can just pipe the output to a file.
man time. Maybe you can create a wrapper and tell Cron to use it as your "shell" or something like that.
Cronitor (https://cronitor.io) is a tool I built exactly for this purpose. It uses http requests to record the start and end of your jobs.
You'll be notified if your job doesn't run on schedule, or if it runs for too long/too short. You can also configure it to send alerts to you via email, sms, but also Slack, Hipchat, Pagerduty and others.
I use the Jenkins CI to do this via its external-monitor-job plugin. Jenkins can track start and end times, track overall execution time over time, save the output of all jobs it tracks, and present success/failure conditions graphically.
https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs

Resources