Skip to content

Commit c88afd5

Browse files
committed
Lock scheduler same minute
1 parent fe00dfb commit c88afd5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Core/Scheduler.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ public static function schedule(Schedule $schedule)
3030

3131
$schedule->call(function () use ($schedulableQueue, $scheduleConfig) {
3232
$className = $schedulableQueue->class_name;
33+
34+
$lockKey = 'QUEUE_LOCK_' . $schedulableQueue->class_name . '_' . date('Y-m-d-H-i');
35+
36+
if (\Cache::has($lockKey)) {
37+
return;
38+
}
39+
40+
$expiresAt = now()->addMinutes(10);
41+
42+
\Cache::put($lockKey, '1', $expiresAt);
43+
3344
if ($scheduleConfig->props && is_array($scheduleConfig->props)) {
3445
foreach($scheduleConfig->props as $prop) {
3546
$job = (new $className());

0 commit comments

Comments
 (0)