From ce853ad8fe42ce565ca2127d2a888507bf60edd6 Mon Sep 17 00:00:00 2001 From: Deeka Wong Date: Tue, 5 Sep 2023 14:35:51 +0800 Subject: [PATCH] Boot trigger processes on main worker start (#331) * Boot trigger processes on main worker start * Rename listener * Revert "Rename listener" This reverts commit 3f8653a992d0d814baf0677f500ee88f5d3bacff. * Rename * Remove listener from ConfigProvider --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com> --- src/ConfigProvider.php | 2 +- src/Listener/BindTriggerProcessesListener.php | 47 +++++++++++++++++++ src/Listener/OnBootApplicationListener.php | 34 ++------------ 3 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 src/Listener/BindTriggerProcessesListener.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 13740be..17ba18a 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -31,7 +31,7 @@ public function __invoke(): array Command\TriggersCommand::class, ], 'listeners' => [ - Listener\OnBootApplicationListener::class, + // Listener\BindTriggerProcessesListener::class, ], 'publish' => [ [ diff --git a/src/Listener/BindTriggerProcessesListener.php b/src/Listener/BindTriggerProcessesListener.php new file mode 100644 index 0000000..b1d1072 --- /dev/null +++ b/src/Listener/BindTriggerProcessesListener.php @@ -0,0 +1,47 @@ +subscriberManager->register(); + $this->triggerManager->register(); + $this->consumerManager->run(); + } +} diff --git a/src/Listener/OnBootApplicationListener.php b/src/Listener/OnBootApplicationListener.php index 175f2ac..19df6c4 100644 --- a/src/Listener/OnBootApplicationListener.php +++ b/src/Listener/OnBootApplicationListener.php @@ -11,35 +11,9 @@ namespace FriendsOfHyperf\Trigger\Listener; -use FriendsOfHyperf\Trigger\ConsumerManager; -use FriendsOfHyperf\Trigger\SubscriberManager; -use FriendsOfHyperf\Trigger\TriggerManager; -use Hyperf\Event\Contract\ListenerInterface; -use Hyperf\Framework\Event\BootApplication; - -class OnBootApplicationListener implements ListenerInterface +/** + * @deprecated v3.0, will be removed in v3.1, please use StartTriggerListener instead. + */ +class OnBootApplicationListener extends BindTriggerProcessesListener { - public function __construct( - protected SubscriberManager $subscriberManager, - protected TriggerManager $triggerManager, - protected ConsumerManager $consumerManager - ) { - } - - public function listen(): array - { - return [ - BootApplication::class, - ]; - } - - /** - * @param BootApplication $event - */ - public function process(object $event): void - { - $this->subscriberManager->register(); - $this->triggerManager->register(); - $this->consumerManager->run(); - } }