0

I want to perform certain job exactly at round times, precisely every 30 minutes, for example:

- 00:00
- 00:30
- 01:00
- ...
- 12:00
- 12:30
- 13:00
- ...

In the Kernel.php, I have this job...

$schedule->command('mycommand:sender')
            ->everyThirtyMinutes();

... and in in the crontab, I have this command...

* * * * * cd /www/webapp && php artisan schedule:run >> /dev/null 2>&1

Apparently everything is ok, but if I stop the service or restart the server, this instructions, either in Kernel or even inCrontab, is correct for, for example, the server or service became available, at "12:29", I know the command will execute from "minute to minute", but "something" from these instructions will know that the next execution "should" be at 12:30 or the way it is, will run "30 minutes" after 12:29, therefore, 12:59?

Although it may seem irrelevant, but I have tasks in my system, that the needs to perform at these "round times", because the task "execution time" determines what will be performed.

Magno Alberto
  • 628
  • 14
  • 27

2 Answers2

0

Add this instead ->everyThirtyMinutes();

cron("*/30 * * * *")

This will be execute from now:

at 2019-12-04 18:00:00
then at 2019-12-04 18:30:00
then at 2019-12-04 19:00:00
then at 2019-12-04 19:30:00
then at 2019-12-04 20:00:00

Patryk
  • 75
  • 4
  • Thanks for the suggestion, I will try, but only so I can understand better. So, based on your suggestion, then this `everyThirtyMinutes() `will always run every 30 minutes, but not round time, but then `cron("*/30 * * * *")` has to have different property? – Magno Alberto Dec 04 '19 at 17:07
-1

Instead of run in cron every minute and check the logic in php why do not make cron to run every 30 minutes?

0,30 * * * * cd /www/webapp && php artisan schedule:run >> /dev/null 2>&1
Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31
  • It's an alternative, but I have other tasks, including one every 15 minutes and others at static times (always at 8:30 and 22:30). My fear is to lose these times, because an execution outside the expected time, the information that comes, no longer matters. – Magno Alberto Dec 04 '19 at 17:28
  • I do not see any problem with this. At the end `cron` is about to run scheduled jobs. And it run them quite well and precise. The tolerance can be only few seconds – Romeo Ninov Dec 04 '19 at 17:30
  • If I change anything, either in the `job` or in the `kernel`, I will need to restart the command `artisan queue:work --daemon`, since this one is running in the background `(php artisan queue:work --daemon --tries=0 > storage/logs/jobs_queue.txt &)`? – Magno Alberto Dec 04 '19 at 17:38
  • Have no idea as I am sysadmin. But probably yes – Romeo Ninov Dec 04 '19 at 17:39