|
|
@@ -8,8 +8,9 @@ use ReflectionClass;
|
|
|
use ReflectionMethod;
|
|
|
use SixShop\Core\Attribute\Cron;
|
|
|
use SixShop\Core\Attribute\Hook;
|
|
|
-use SixShop\System\Event\CronJobAfterEvent;
|
|
|
-use SixShop\System\Event\CronJobBeforeEvent;
|
|
|
+use SixShop\System\Event\CronJobFailed;
|
|
|
+use SixShop\System\Event\CronJobProcessed;
|
|
|
+use SixShop\System\Event\CronJobProcessing;
|
|
|
use SixShop\System\Event\CrontabWorkerStartEvent;
|
|
|
use SixShop\System\Event\GetCronJobsEvent;
|
|
|
use SixShop\System\ExtensionManager;
|
|
|
@@ -32,29 +33,32 @@ class GatheringCrontabEventHook
|
|
|
private function wrapCallback(callable $callback, string $name, string $rule, object $target): callable
|
|
|
{
|
|
|
return function () use ($callback, $name, $rule, $target) {
|
|
|
- $this->app->event->trigger(new CronJobBeforeEvent($name, $rule, $target));
|
|
|
+ $this->app->event->trigger(new CronJobProcessing($name, $rule, $target));
|
|
|
|
|
|
$startTime = microtime(true);
|
|
|
- $throwable = null;
|
|
|
$result = null;
|
|
|
|
|
|
try {
|
|
|
$result = $callback();
|
|
|
- } catch (\Throwable $e) {
|
|
|
- $throwable = $e;
|
|
|
- Log::error("Cron job [{$name}] failed: " . $e->getMessage());
|
|
|
- }
|
|
|
|
|
|
- $duration = microtime(true) - $startTime;
|
|
|
+ $this->app->event->trigger(new CronJobProcessed(
|
|
|
+ name: $name,
|
|
|
+ rule: $rule,
|
|
|
+ target: $target,
|
|
|
+ startTime: $startTime,
|
|
|
+ result: $result,
|
|
|
+ ));
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ Log::error("Cron job [{$name}] failed: " . (string) $e);
|
|
|
|
|
|
- $this->app->event->trigger(new CronJobAfterEvent(
|
|
|
- name: $name,
|
|
|
- rule: $rule,
|
|
|
- target: $target,
|
|
|
- result: $result,
|
|
|
- duration: round($duration, 4),
|
|
|
- throwable: $throwable,
|
|
|
- ));
|
|
|
+ $this->app->event->trigger(new CronJobFailed(
|
|
|
+ name: $name,
|
|
|
+ rule: $rule,
|
|
|
+ target: $target,
|
|
|
+ throwable: $e,
|
|
|
+ startTime: $startTime,
|
|
|
+ ));
|
|
|
+ }
|
|
|
};
|
|
|
}
|
|
|
|