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.
Related
We have read https://developer.shopware.com/docs/guides/plugins/plugins/plugin-fundamentals/add-scheduled-task which described how to define a scheduled tasks which runs every x minutes.
Is it also possible to specific the execution time, for example each midnight or every day a 2 am, like in a crontab?
There is no such possibility in Shopware 6. It is easier to accomplish this with a CLI command and crontab. But if you have to use Shopware's scheduled task then you can trick it by setting the nextExecutionTime to the time you want to execute the task.
For example if today's date is 10.03.2022 and you want to execute the scheduled task every day at 2 am then set the nextExecutionTime to 2022-03-11 00:02:00.000 (use future date) and runInterval to 86400 (24h). This way Shopware will start the task at 2 am and then set the nextExecutionTime to the next day at 2 am (+- couple of minutes from my experience).
I'm not aware of such a feature in Shopware core.
The probably most straightforward way would be to add a "real" cronjob like you mentioned, which triggers a CLI-command.
You can encapsulate the logic of the task in it's own service, so that the scheduled task and cli-command both can just use the service (if you want to keep both).
I see on the scheduled script deployment screen on Netsuite, the Repeat dropdown starts with a minimum of every 15 minutes. Can the interval be shortened somehow?
The interval of scheduled scripts cannot be shortened to less than 15 minutes.
What you can do is set up a Suitelet that triggers the scheduled script to start. Once you get the External URL of the Suitelet you can plug it into an external cronjob service such as https://cron-job.org and set it to run every 3 minutes.
Note that the scheduled script would be put on a queue either way so it may not start immediately after.
The answer would be No. I think they are trying to prevent choking the queue so they only allow 15mins.
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.
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
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