Add callback to resolve custom mutex name of schedule events #45126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello 👋
we have created schedule tasks monitoring and history module, we are passing uuid to every schedule task (this uuid is different on every server every time) to identify specific runs.
We are using
withoutOverlapping
andonOneServer
but we had some issues since mutex name of scheduled tasks are generated from full command string. This may be okay for hardcoded scheduled tasks in kernel but not so good for dynamically created scheduled tasks (ie via database) while attaching different parameters to commands. (We want to share mutex / lock between those cron runs on multiple servers.)I have added simple method to allow developers to use custom defined mutex name of each of scheduled tasks.
This could be done by using
preventOverlapsUsing
and creating new implementation ofIlluminate\Console\Scheduling\EventMutex
interface, however this is not really necessary since we do not want to change logic how mutex is created, forgotten etc. We just want to change name of mutex (key).This can be also used for blocking one scheduled command until other command is finished.
Example usage: