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

preventOverlapping not working on closures #314

Closed
g19i85g opened this issue Sep 8, 2020 · 3 comments
Closed

preventOverlapping not working on closures #314

g19i85g opened this issue Sep 8, 2020 · 3 comments
Labels
Milestone

Comments

@g19i85g
Copy link

g19i85g commented Sep 8, 2020

Crunz version: 2.2.0

PHP version: 7.3.19

Description
The method preventOverlapping() does not work.

How to reproduce
Create a long running task and let it run every minute.
After a few minutes you can see that the task runs several times.

use Crunz\Schedule;

$schedule = new Schedule();
$task = $schedule->run(
    static function () {
        sleep(500);

        return true;
    }
);
$task->everyMinute()
     ->preventOverlapping();

return $schedule;

Additional context
I found out that the method \Crunz\Event::lockKey() creates a new key every time I start the run command.

public function serialize()
    {
        ...
        $this->reference = spl_object_hash($this->closure);
       ...
        $ret = \serialize(array(
            ...
             'self' => $this->reference,
         ));
       ...
    }

I suppose the part of the method \Opis\Closure\SerializableClosure::serialize() is the cause.

@PabloKowalczyk
Copy link
Collaborator

Hello, after #313 you can specify lockKey yourself, that should resolve the problem.

@g19i85g
Copy link
Author

g19i85g commented Sep 9, 2020

Yes, that's true but from my point of view this is more of a workaround. Maybe you could make it mandatory to hand over the key when using closures.

@PabloKowalczyk
Copy link
Collaborator

Fixed by #326, thanks @g19i85g.

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

No branches or pull requests

2 participants