Skip to content

Commit 87e8b11

Browse files
committed
Fix schedulable
1 parent 19b6b79 commit 87e8b11

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

src/Core/Scheduler.php

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,51 @@ public static function schedule(Schedule $schedule)
1616

1717
$scheduleConfig = json_decode($schedulableQueue->schedule_config);
1818

19-
if (!isset($scheduleConfig->method)) {
20-
event(new ScheduleError('Method not configured for ' . $schedulableQueue->name, ['command' => 'reread']));
21-
continue;
22-
}
19+
try {
2320

24-
$method = $scheduleConfig->method;
21+
if (!isset($scheduleConfig->method)) {
22+
event(new ScheduleError('ScheduleError - Method not configured for ' . $schedulableQueue->name));
23+
continue;
24+
}
2525

26-
$params = '';
27-
if (isset($scheduleConfig->params)) {
28-
$params = $scheduleConfig->params;
29-
}
26+
$method = $scheduleConfig->method;
3027

31-
$schedule->call(function () use ($schedulableQueue, $scheduleConfig) {
32-
$className = $schedulableQueue->class_name;
28+
$params = '';
29+
if (isset($scheduleConfig->params)) {
30+
$params = $scheduleConfig->params;
31+
}
3332

34-
$lockKey = 'QUEUE_LOCK_' . $schedulableQueue->name . '_' . date('Y-m-d-H-i');
33+
$schedule->call(function () use ($schedulableQueue, $scheduleConfig) {
34+
$className = $schedulableQueue->class_name;
3535

36-
if (\Cache::has($lockKey)) {
37-
return;
38-
}
39-
40-
$expiresAt = now()->addMinutes(10);
36+
$lockKey = 'QUEUE_LOCK_' . $schedulableQueue->name . '_' . date('Y-m-d-H-i');
4137

42-
\Cache::put($lockKey, '1', $expiresAt);
43-
44-
if ($scheduleConfig->props && is_array($scheduleConfig->props)) {
45-
foreach($scheduleConfig->props as $prop) {
38+
if (\Cache::has($lockKey)) {
39+
return;
40+
}
41+
42+
$expiresAt = now()->addMinutes(10);
43+
44+
\Cache::put($lockKey, '1', $expiresAt);
45+
46+
if ($scheduleConfig->props && is_array($scheduleConfig->props)) {
47+
foreach($scheduleConfig->props as $prop) {
48+
$job = (new $className());
49+
$job->setName($schedulableQueue->name);
50+
$job->setProps($prop);
51+
$job->dispatch();
52+
}
53+
} else {
4654
$job = (new $className());
4755
$job->setName($schedulableQueue->name);
48-
$job->setProps($prop);
4956
$job->dispatch();
5057
}
51-
} else {
52-
$job = (new $className());
53-
$job->setName($schedulableQueue->name);
54-
$job->dispatch();
55-
}
56-
})->$method($params);
58+
})->$method($params);
59+
60+
61+
} catch (\Throwable $e) {
62+
event(new ScheduleError('Schedule Error - ' . $schedulableQueue->name . ' ' . $e->getMessage()));
63+
}
5764
}
5865
}
5966

0 commit comments

Comments
 (0)