CronManager Extra set specific time?

I’m wondering if I’m overlooking something really obvious, but I can’t seem to set a specific time to execute a task using the CronManager Extra. I can only set a specific value in minutes which is the interval of the task but only AFTER executing it once, setting the initial time thereby.

But I would like to set the execution ideally by the general known cron format (* * * * *) because I need the script to be fired at a specific time (where I don’t necessarily want to be awake to start it).

So is there an option for that? If not can the extra be adjusted manually? (Or maybe @jako is even open for a feature request like this?)

MODX 2.8.6

If you have only one snippet that you want to run with the CronManager extra, I believe you could just set a specific time for the cronjob on the server (and then set a small interval in CronManager, so that the snippet is executed every time the cronjob runs).

1 Like

I guess the easiest way to achieve the desired execution times is by going directly to the database and changing the times there. I think it would be nice, if this functionality would be included in the extra itself.

If I recall correctly, CronManager isn’t really good at keeping to a fixed time.

Let’s say you want to make a database backup every night at 2 o’clock.
So you set the interval to 1’440 minutes (24 * 60) and tell the cronjob to call cron.php every minute. The result is, that the actual interval will likely be 1’441 minutes! (As it takes some time to execute the script, the next run is delayed by one cronjob-call).
You let this run for a year without paying attention, and the backup now occurs 6 hours later.

So it’s better to call cron.php just once a day (at a specified time) if there’s only one snippet to run.

The way I observed it so far is that CronManager takes the initial time of the first execution of the script and then calculates the next run depending on that timestamp while adding the minute amount.

So if I start a script at 12:00pm and have minutes set to 720, the next run time is set to 12:00am. So far it doesn’t seem to loose the time the script takes, it just takes the timestamp when the script is initiated, but I will definitely keep an eye on it.

That being said, I need the script to be executed twice per day at this moment, although that might change and I might need to add more scripts with inidivdual time schedules.

That’s why I was wondering why there is no better option to specifically set execution times in the typical cron format as this would make things much easier.

The calculation of the nextrun should not add any runtime of the executed script. According to the code it adds fixed minutes to to the last runtime.

It is quite difficult to add the crontab syntax there without changing the backwards compatibility. But is is somehow possible to add the nextrun field in the create/update popup.

The interval isn’t added to the last time the snippet ran.
It’s gets added to the current time → $rundatetime = date('Y-m-d H:i:s');:

So if “cron.php” is always executed exactly on the time set by the cronjob, this works correclty.
But if “cron.php” is occasionally called a second or two too late, then the execution time of the snippet will be delayed for a minute each time.

Cronjobs are normally meant to be run at an exact time (I know that other run options are possible with cron.hourly, cron.daily etc). It is fixed with 1.3.2.

@vibedesign I have added an editable next run field in the create/update window.

2 Likes

This is great, Jako, thanks the fixes!