Skip to content

Commit

Permalink
Boot trigger processes on main worker start (#331)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
huangdijia and huangdijia authored Sep 5, 2023
1 parent 781326f commit ce853ad
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(): array
Command\TriggersCommand::class,
],
'listeners' => [
Listener\OnBootApplicationListener::class,
// Listener\BindTriggerProcessesListener::class,
],
'publish' => [
[
Expand Down
47 changes: 47 additions & 0 deletions src/Listener/BindTriggerProcessesListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);
/**
* This file is part of friendsofhyperf/components.
*
* @link https://github.com/friendsofhyperf/components
* @document https://github.com/friendsofhyperf/components/blob/main/README.md
* @contact [email protected]
*/

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\MainWorkerStart;
use Hyperf\Server\Event\MainCoroutineServerStart;

class BindTriggerProcessesListener implements ListenerInterface
{
public function __construct(
protected SubscriberManager $subscriberManager,
protected TriggerManager $triggerManager,
protected ConsumerManager $consumerManager
) {
}

public function listen(): array
{
return [
MainWorkerStart::class,
MainCoroutineServerStart::class,
];
}

/**
* @param MainWorkerStart|MainCoroutineServerStart $event
*/
public function process(object $event): void
{
$this->subscriberManager->register();
$this->triggerManager->register();
$this->consumerManager->run();
}
}
34 changes: 4 additions & 30 deletions src/Listener/OnBootApplicationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit ce853ad

Please sign in to comment.