-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Deeka Wong <[email protected]>
- Loading branch information
1 parent
131d391
commit e9f56c0
Showing
25 changed files
with
320 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"friendsofhyperf", | ||
"friendsofphp", | ||
"krowinski", | ||
"moln", | ||
"nums" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,13 @@ | |
* @document https://github.com/friendsofhyperf/trigger/blob/main/README.md | ||
* @contact [email protected] | ||
*/ | ||
use function Hyperf\Support\env; | ||
|
||
return [ | ||
'pools' => [ | ||
'connections' => [ | ||
'default' => [ | ||
'enable' => env('TRIGGER_ENABLE', true), | ||
|
||
'host' => env('TRIGGER_HOST', ''), | ||
'port' => (int) env('TRIGGER_PORT', 3306), | ||
'user' => env('TRIGGER_USER', ''), | ||
|
@@ -40,6 +44,8 @@ | |
'concurrent' => [ | ||
'limit' => 1000, | ||
], | ||
|
||
'consume_timeout' => 600, | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of hyperf-trigger. | ||
* | ||
* @link https://github.com/friendsofhyperf/trigger | ||
* @document https://github.com/friendsofhyperf/trigger/blob/main/README.md | ||
* @contact [email protected] | ||
*/ | ||
namespace FriendsOfHyperf\Trigger\Aspect; | ||
|
||
use Hyperf\Di\Aop\AbstractAspect; | ||
use Hyperf\Di\Aop\ProceedingJoinPoint; | ||
use MySQLReplication\BinaryDataReader\BinaryDataReader; | ||
|
||
/** | ||
* @mixin BinaryDataReader | ||
*/ | ||
class BinaryDataReaderAspect extends AbstractAspect | ||
{ | ||
public array $classes = [ | ||
BinaryDataReader::class . '::readUIntBySize', | ||
]; | ||
|
||
public function process(ProceedingJoinPoint $proceedingJoinPoint) | ||
{ | ||
if ($proceedingJoinPoint->arguments['keys']['size'] == BinaryDataReader::UNSIGNED_INT64_LENGTH) { | ||
return (fn () => (int) $this->readUInt64())->call($proceedingJoinPoint->getInstance()); | ||
} | ||
|
||
return $proceedingJoinPoint->process(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of hyperf-trigger. | ||
* | ||
* @link https://github.com/friendsofhyperf/trigger | ||
* @document https://github.com/friendsofhyperf/trigger/blob/main/README.md | ||
* @contact [email protected] | ||
*/ | ||
namespace FriendsOfHyperf\Trigger\Command; | ||
|
||
use FriendsOfHyperf\CommandSignals\Traits\InteractsWithSignals; | ||
use FriendsOfHyperf\Trigger\Consumer; | ||
use Hyperf\Command\Annotation\Command; | ||
use Hyperf\Command\Command as HyperfCommand; | ||
use Hyperf\Contract\ConfigInterface; | ||
use Hyperf\Coordinator\CoordinatorManager; | ||
use Hyperf\Coroutine\Coroutine; | ||
use Psr\Container\ContainerInterface; | ||
|
||
use function Hyperf\Support\make; | ||
|
||
#[Command()] | ||
class ConsumeCommand extends HyperfCommand | ||
{ | ||
use InteractsWithSignals; | ||
|
||
protected ?string $signature = 'trigger:consume'; | ||
|
||
protected string $description = 'Run consumers.'; | ||
|
||
public function __construct( | ||
protected ContainerInterface $container, | ||
protected ConfigInterface $config | ||
) { | ||
} | ||
|
||
public function handle() | ||
{ | ||
$consumers = $this->getConsumers(); | ||
|
||
$this->trap([SIGINT, SIGTERM], function ($signo) use ($consumers) { | ||
$this->warn(sprintf('Received signal %d, exiting...', $signo)); | ||
|
||
foreach ($consumers as $consumer) { | ||
$consumer->stop(); | ||
} | ||
|
||
CoordinatorManager::until(self::class)->resume(); | ||
}); | ||
|
||
foreach ($consumers as $consumer) { | ||
Coroutine::create(function () use ($consumer) { | ||
$consumer->start(); | ||
}); | ||
} | ||
|
||
CoordinatorManager::until(self::class)->yield(); | ||
|
||
$this->info('Bye!'); | ||
} | ||
|
||
/** | ||
* @return Consumer[] | ||
*/ | ||
public function getConsumers(): array | ||
{ | ||
$consumers = []; | ||
$connections = $this->config->get('trigger.connections', []); | ||
|
||
foreach ($connections as $connection => $options) { | ||
if (isset($options['enable']) && ! $options['enable']) { | ||
continue; | ||
} | ||
|
||
$consumers[] = make(Consumer::class, [ | ||
'connection' => $connection, | ||
'options' => (array) $options, | ||
]); | ||
} | ||
|
||
return $consumers; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.