TaskSchedulerBundle icon indicating copy to clipboard operation
TaskSchedulerBundle copied to clipboard

Printing in initialize function cancels CRON's recurrency

Open Zasco opened this issue 6 years ago • 8 comments

Any kind of text printing (echo, print_r, var_dump) used in a task's initialize() will make it's Cron fire every minute instead of the configured expression. However, the Cron's expression is the configured one and isDue is TRUE. Log says task is run as usual.

This is not so bad, but you have to know.

Zasco avatar Feb 15 '19 22:02 Zasco

Why would it run every 5 minutes when printing something ? Why precisely 5 minutes ? Any source code to show? Thanks

ancyrweb avatar Feb 19 '19 08:02 ancyrweb

I didn't say « five (5) » but « fire ». Sorry for the misunderstanding. In other words, the task is run every minute (* * * * *) no matter how it is scheduled.

Zasco avatar Feb 19 '19 12:02 Zasco

is this still relevant?

marcin-derlukiewicz avatar Feb 03 '21 14:02 marcin-derlukiewicz

I experimented it a few months ago, and yes it is the case. I didn't have time to fill in a PR so I had to workaround with supervisord but that should definetely be fixed with a major version bump as it would probably break backward compatibility.

ancyrweb avatar Feb 03 '21 16:02 ancyrweb

i just want to confirm something.

you run cron every minute, this cron starts a process, that searches all classes extending interface using symfony's tagging for every found class it tries to determine if it should be run in current minute and in consequence launches initialize method to check it ( and here print or var_dump happens ). now assumption is that if task should not be run, it won't, but it happens anyway, right?

I mean, it should work like that: initialize will be run, but it does not means, that task was run, but the effect is, that task is run anyway?

marcin-derlukiewicz avatar Feb 04 '21 11:02 marcin-derlukiewicz

What makes you think that a task is run all the time? run of a task is only executed if isDue returns true. If you have seen other behaviour, can you share sample code that triggers this?

Even that search for all scheduled tasks should not happen every time, but only once (during container build time)

NicoHaase avatar Feb 04 '21 16:02 NicoHaase

anyway, I tried with both, echo and var dump and it works as expected, task is not run, and echo is printed at kernel boot (and that happens every time you run ts:run command, but it doesn't mean that task is run by itself).


src/**/Task/LoadOpenOrdersTask.php:47:
string(3) "aaa"
22:51:56 INFO      [scheduler] [08/02/21 22:51:56] Starting...
22:51:57 INFO      [scheduler] Skipped App\**\Task\LoadOpenOrdersTask
22:51:57 INFO      [scheduler] Running App\**\Task\SendPriceListTask

can you run ts:run with more verbose logger (-vvv) and/or provide code that triggers this?

marcin-derlukiewicz avatar Feb 08 '21 22:02 marcin-derlukiewicz

should we just close this?

marcin-derlukiewicz avatar Feb 17 '21 10:02 marcin-derlukiewicz