Skip to content

Printing in initialize function cancels CRON's recurrency #6

Open

Description

@Zasco

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.

Activity

  1. ancyrweb commented on Feb 19, 2019

    @ancyrweb
    Owner

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

  2. Zasco commented on Feb 19, 2019

    @Zasco
    ContributorAuthor

    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.

  3. marcin-derlukiewicz commented on Feb 3, 2021

    @marcin-derlukiewicz
    Contributor

    is this still relevant?

  4. ancyrweb commented on Feb 3, 2021

    @ancyrweb
    Owner

    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.

  5. marcin-derlukiewicz commented on Feb 4, 2021

    @marcin-derlukiewicz
    Contributor

    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?

  6. NicoHaase commented on Feb 4, 2021

    @NicoHaase
    Collaborator

    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)

  7. marcin-derlukiewicz commented on Feb 8, 2021

    @marcin-derlukiewicz
    Contributor

    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?

  8. marcin-derlukiewicz commented on Feb 17, 2021

    @marcin-derlukiewicz
    Contributor

    should we just close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions