改名
This commit is contained in:
@@ -47,21 +47,21 @@ class OnPipeMessage extends Callback
|
||||
throw new Exception('unknown handler');
|
||||
}
|
||||
/** @var Crontab $handler */
|
||||
$handler = $message['handler'];
|
||||
$handler = swoole_unserialize($message['handler']);
|
||||
defer(function () use ($handler) {
|
||||
$return = $handler->isRecover();
|
||||
if ($return === 999) {
|
||||
$name = $handler->getName();
|
||||
|
||||
if ($handler->isRecover() !== 999) {
|
||||
return;
|
||||
}
|
||||
$redis = Snowflake::app()->getRedis();
|
||||
if ($redis->exists('stop:crontab:' . $name)) {
|
||||
$redis->del('crontab:' . $name);
|
||||
$redis->del('stop:crontab:' . $name);
|
||||
} else {
|
||||
|
||||
$name = $handler->getName();
|
||||
if (!$redis->exists('stop:crontab:' . $name)) {
|
||||
$redis->set('crontab:' . $name, swoole_serialize($handler));
|
||||
$tickTime = time() + $handler->getTickTime();
|
||||
$redis->zAdd(Producer::CRONTAB_KEY, $tickTime, $name);
|
||||
}
|
||||
} else {
|
||||
$redis->del('crontab:' . $name);
|
||||
$redis->del('stop:crontab:' . $name);
|
||||
}
|
||||
});
|
||||
$handler->increment()->execute();
|
||||
|
||||
+32
-3
@@ -10,7 +10,8 @@ use RdKafka\ConsumerTopic;
|
||||
use RdKafka\Exception;
|
||||
use RdKafka\KafkaConsumer;
|
||||
use RdKafka\TopicConf;
|
||||
use Snowflake\Core\Json;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Coroutine\Channel;
|
||||
use Swoole\Coroutine\System;
|
||||
@@ -29,19 +30,47 @@ class Kafka extends \Snowflake\Process\Process
|
||||
private int $maxLength = 5000;
|
||||
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $kafkaConfig = [];
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function getProcessName(): string
|
||||
{
|
||||
$this->kafkaConfig = swoole_unserialize($this->read());
|
||||
|
||||
$name = Config::get('id', 'system') . '[' . $this->pid . ']';
|
||||
|
||||
return $name . '.' . 'Kafka Consumer ' . $this->kafkaConfig['topic'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function onHandler(Process $process): void
|
||||
public function before(Process $process): void
|
||||
{
|
||||
$content = System::readFile(storage('runtime.php'));
|
||||
|
||||
$annotation = Snowflake::app()->getAnnotation();
|
||||
$annotation->setLoader(unserialize($content));
|
||||
$annotation->runtime(KAFKA_PATH);
|
||||
}
|
||||
|
||||
$this->waite(swoole_unserialize($process->read()));
|
||||
|
||||
/**
|
||||
* @param Process $process
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function onHandler(Process $process): void
|
||||
{
|
||||
$this->waite($this->kafkaConfig);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use Exception;
|
||||
use HttpServer\Server;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Cache\Redis;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Process\Process;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Coroutine;
|
||||
@@ -28,7 +29,8 @@ class Zookeeper extends Process
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
* @return string
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function getProcessName(): string
|
||||
{
|
||||
@@ -85,7 +87,7 @@ class Zookeeper extends Process
|
||||
if (empty($handler = $redis->get('crontab:' . $value))) {
|
||||
return;
|
||||
}
|
||||
$params['handler'] = unserialize($handler);
|
||||
$params['handler'] = $handler;
|
||||
|
||||
$this->server->sendMessage($params, $this->getWorker());
|
||||
} catch (Throwable $exception) {
|
||||
@@ -105,8 +107,8 @@ class Zookeeper extends Process
|
||||
|
||||
|
||||
/**
|
||||
* @param Redis|\Redis $redis
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function loadCarobTask(Redis|\Redis $redis): array
|
||||
{
|
||||
|
||||
@@ -21,6 +21,19 @@ class LoggerProcess extends Process
|
||||
{
|
||||
|
||||
|
||||
public function before(\Swoole\Process $process): void
|
||||
{
|
||||
// TODO: Implement before() method.
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getProcessName(): string
|
||||
{
|
||||
// TODO: Implement getProcessName() method.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
* @throws ComponentException
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Snowflake\Process;
|
||||
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Timer;
|
||||
|
||||
@@ -16,6 +17,25 @@ class Biomonitoring extends Process
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
*/
|
||||
public function before(\Swoole\Process $process): void
|
||||
{
|
||||
// TODO: Implement before() method.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
#[Pure] public function getProcessName(): string
|
||||
{
|
||||
// TODO: Implement getProcessName() method.
|
||||
return get_called_class();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
* @throws Exception
|
||||
|
||||
@@ -8,10 +8,18 @@ interface SProcess
|
||||
{
|
||||
|
||||
|
||||
// public function getProcessName(): string;
|
||||
//
|
||||
//
|
||||
// public function before(\Swoole\Process $process): void;
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* return process name
|
||||
*/
|
||||
public function getProcessName(): string;
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
*/
|
||||
public function before(\Swoole\Process $process): void;
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
|
||||
@@ -12,10 +12,8 @@ namespace Snowflake\Process;
|
||||
|
||||
use Exception;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Event;
|
||||
use Swoole\Timer;
|
||||
|
||||
@@ -37,16 +35,36 @@ class ServerInotify extends Process
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
* @throws Exception
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function onHandler(\Swoole\Process $process): void
|
||||
public function before(\Swoole\Process $process): void
|
||||
{
|
||||
// TODO: Implement before() method.
|
||||
set_error_handler([$this, 'onErrorHandler']);
|
||||
$this->dirs = Config::get('inotify', [APP_PATH]);
|
||||
if (extension_loaded('inotify')) {
|
||||
$this->inotify = inotify_init();
|
||||
$this->events = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProcessName(): string
|
||||
{
|
||||
return 'file change process';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
* @throws Exception
|
||||
*/
|
||||
public function onHandler(\Swoole\Process $process): void
|
||||
{
|
||||
if (extension_loaded('inotify')) {
|
||||
foreach ($this->dirs as $dir) {
|
||||
if (!is_dir($dir)) continue;
|
||||
$this->watch($dir);
|
||||
|
||||
Reference in New Issue
Block a user