|
|
@@ -11,6 +11,7 @@ use SixShop\System\Event\CrontabWorkerStartEvent;
|
|
|
use SixShop\System\Event\GetCronJobsEvent;
|
|
|
use SixShop\System\ExtensionManager;
|
|
|
use think\App;
|
|
|
+use think\facade\Log;
|
|
|
use Workerman\Crontab\Crontab;
|
|
|
use function SixShop\Core\extension_name_list;
|
|
|
|
|
|
@@ -40,12 +41,22 @@ class GatheringCrontabEventHook
|
|
|
$this->app->event->trigger($event);
|
|
|
foreach ($event as $cronJobClass) {
|
|
|
$ref = new ReflectionClass($cronJobClass);
|
|
|
+ $objectAttts = $ref->getAttributes(Cron::class);
|
|
|
+ $cronJob = $this->app->make($cronJobClass);
|
|
|
+ foreach ($objectAttts as $attribute) {
|
|
|
+ $cronInstance = $attribute->newInstance();
|
|
|
+ if (is_callable($cronJob)) {
|
|
|
+ new Crontab($cronInstance->rule, $cronJob, $cronInstance->name?:$cronJobClass);
|
|
|
+ } else {
|
|
|
+ Log::warning("Cron job {$cronJobClass} is not callable");
|
|
|
+ }
|
|
|
+ }
|
|
|
foreach ($ref->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
|
|
|
$attributes = $method->getAttributes(Cron::class);
|
|
|
foreach ($attributes as $attribute) {
|
|
|
$cronInstance = $attribute->newInstance();
|
|
|
$name = $cronInstance->name ?: $cronJobClass . '@' . $method->getName();
|
|
|
- new Crontab($cronInstance->rule, [$this->app->make($cronJobClass), $method->getName()], $name);
|
|
|
+ new Crontab($cronInstance->rule, [$cronJob, $method->getName()], $name);
|
|
|
}
|
|
|
}
|
|
|
}
|