|
|
@@ -9,8 +9,10 @@ use SixShop\Core\Attribute\Cron;
|
|
|
use SixShop\Core\Attribute\Hook;
|
|
|
use SixShop\Core\Helper;
|
|
|
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;
|
|
|
|
|
|
class GatheringCrontabEventHook
|
|
|
@@ -23,18 +25,25 @@ class GatheringCrontabEventHook
|
|
|
public function onWorkerStart(): void
|
|
|
{
|
|
|
$extensionManager = $this->app->make(ExtensionManager::class);
|
|
|
+ $event = new GetCronJobsEvent();
|
|
|
+
|
|
|
foreach (Helper::extension_name_list() as $extensionName) {
|
|
|
$extension = $extensionManager->getExtension($extensionName);
|
|
|
$cronJobs = $extension->getCronJobs();
|
|
|
foreach ($cronJobs as $cronJobClass) {
|
|
|
- $ref = new ReflectionClass($cronJobClass);
|
|
|
- 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);
|
|
|
- }
|
|
|
+ $event->push($cronJobClass);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->app->event->trigger($event);
|
|
|
+ foreach ($event as $cronJobClass) {
|
|
|
+ $ref = new ReflectionClass($cronJobClass);
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
}
|