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 for distinct tasks #313

Open
archonia-chris opened this issue Sep 1, 2020 · 3 comments
Open

preventOverlapping for distinct tasks #313

archonia-chris opened this issue Sep 1, 2020 · 3 comments

Comments

@archonia-chris
Copy link

archonia-chris commented Sep 1, 2020

Description
preventOverlapping allows to skip a task if the previous execution is still running. Sometimes there are multiple distinct tasks that shouldn't run concurrently. If we are allowed to set "lockKey", we can easily accomplish that.

Example
One way to provide this feature would be as an extra parameter to preventOverlapping that overrides "lockKey".

// Task1 
$schedule->run('/usr/bin/php dosomething.php')
         ->everyFiveMinutes()
         ->preventOverlapping( null, 'theonelock' );

// Task2
$schedule->run('/usr/bin/php dosomethingelse.php')
         ->everyTenMinutes()
         ->preventOverlapping( null, 'theonelock' );

Code
private function lockKey() { return $this->custom_lockkey ?? 'crunz-' . \md5($this->buildCommand()); }

@PabloKowalczyk
Copy link
Collaborator

Hello,

i like your idea, but with a little different API. New method on Event class should do the job, for example:

public function lockKey(string $key): self;

Would you like to provide a PR?

@archonia-chris
Copy link
Author

There is already a function lockKey on the Event class
private function lockKey()
Should that one be renamed?

archonia-chris added a commit to archonia/crunz that referenced this issue Sep 3, 2020
archonia-chris added a commit to archonia/crunz that referenced this issue Sep 3, 2020
@PabloKowalczyk
Copy link
Collaborator

There is already a function lockKey on the Event class
private function lockKey()
Should that one be renamed?

Yes, it is internal method and can be renamed safely.

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