This commit is contained in:
2021-04-15 18:18:41 +08:00
parent 47c1ab2086
commit bd57ba367a
2 changed files with 103 additions and 95 deletions
+4 -1
View File
@@ -9,7 +9,6 @@ use HttpServer\Abstracts\Callback;
use Kafka\Struct;
use Snowflake\Crontab\Crontab;
use Snowflake\Event;
use Snowflake\Exception\ComponentException;
use Swoole\Server;
/**
@@ -50,6 +49,10 @@ class OnPipeMessage extends Callback
{
/** @var Crontab $crontab */
$crontab = $message['handler'] ?? null;
if (!isset($message['handler'])) {
throw new Exception('unknown handler');
}
$crontab = swoole_unserialize($crontab['handler']);
$crontab->increment()->execute();
return 'success';
}
+10 -5
View File
@@ -5,12 +5,12 @@ namespace Snowflake\Crontab;
use Exception;
use Snowflake\Cache\Redis;
use Snowflake\Process\Process;
use Snowflake\Snowflake;
use Swoole\Coroutine\WaitGroup;
use Swoole\Coroutine\Channel;
use Swoole\Coroutine\WaitGroup;
use Swoole\Timer;
use Snowflake\Cache\Redis;
/**
* Class Zookeeper
@@ -65,9 +65,14 @@ class Zookeeper extends Process
*/
private function dispatch($server, Redis|\Redis $redis, int $setting, $value)
{
$server->sendMessage([
'action' => 'crontab', 'handler' => swoole_unserialize($redis->get('crontab:' . $value))
], random_int(0, $setting - 1));
try {
$params['action'] = 'crontab';
$params['handler'] = $redis->get('crontab:' . $value);
$server->sendMessage($params, random_int(0, $setting - 1));
} catch (\Throwable $exception) {
logger()->addError($exception);
}
}