Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task running before the previous task is finished #105

Open
elvispdosreis opened this issue Jun 30, 2020 · 2 comments
Open

Task running before the previous task is finished #105

elvispdosreis opened this issue Jun 30, 2020 · 2 comments

Comments

@elvispdosreis
Copy link

<?php

this task will always be performed

   $scheduler->call(function () use (&$mercadolivre) {
        $mercadolivre->duplicateAttributes();
    })->at('0 0,12 * * *')->then(function ($output) use (&$logger) {
        if (!empty($output)) {
            $logger->error("MercadoLivre Duplicate Attributes - {$output}");
        }
    }, true);

I need the task to run only once until the end of the execution, even if the scheduler is called, this task should not be executed, before it ends

    $scheduler->call(function () use (&$mercadolivre) {
        $mercadolivre->messaging();
    })->at('* * * * *')->then(function ($output) use (&$logger) {
        if (!empty($output)) {
            $logger->error("MercadoLivre Messaging - {$output}");
        }
    }, true)->onlyOne();

as it is today, it is always executed.

@peppeocchi
Copy link
Owner

@elvispdosreis I am not sure I am following, you have 2 tasks running, you want one of the two to run only once, is that correct? And the second currently gets executed multiple times even though you are calling the onlyOne?

You should check if the the lock files are being generated correctly, they're based on a signature of the function, it would be better to pass a custom identifier (https://github.com/peppeocchi/php-cron-scheduler#scheduling-jobs)

Just keep in mind that because you're using Closures, your tasks will run synchronously, so the second one will run after the first one is complete. My suggestion would be to call external scripts and schedule those external scripts so they can both run asynchronously.

To recap:

  • check if the lock files are being generated correctly
  • use a custom identifier
  • move your code to external scripts and have the scheduler just to deal with executing async those script

@elvispdosreis
Copy link
Author

The scheduler is creating the lock file correctly with the task id, he is creating tasks

$scheduler->call(function (MercadoLivre $mercadolivre) {
        $mercadolivre->messaging();
    }, [$mercadolivre], 'mercadoLivre-messaging')->at('* * * * *')->then(function ($output) {
        // ...
    }, true)->onlyOne(ROOT_PATH . '/tmp');

however if I kill the process or he dies the lock file continues

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants