This commit is contained in:
as2252258@163.com
2021-04-11 15:38:23 +08:00
parent d4b64c3af2
commit 60fa2cb896
3 changed files with 136 additions and 120 deletions
+15 -1
View File
@@ -39,10 +39,22 @@ class Consumer extends Process
go(function () { go(function () {
$this->popChannel(); $this->popChannel();
}); });
$this->recovery();
$this->tick($process); $this->tick($process);
} }
private function recovery()
{
$redis = redis()->hGetAll('crontab:wait:execute');
foreach ($redis as $redi) {
$this->channel->push($redi);
}
fire(Event::SYSTEM_RESOURCE_RELEASES);
}
/** /**
* @throws Exception * @throws Exception
*/ */
@@ -59,7 +71,7 @@ class Consumer extends Process
Consumer::addTask($crontab); Consumer::addTask($crontab);
} }
} catch (\Throwable $throwable) { } catch (\Throwable $throwable) {
logger()->addError($throwable,'throwable'); logger()->addError($throwable, 'throwable');
} finally { } finally {
fire(Event::SYSTEM_RESOURCE_RELEASES); fire(Event::SYSTEM_RESOURCE_RELEASES);
} }
@@ -82,7 +94,9 @@ class Consumer extends Process
$redis = Snowflake::app()->getRedis(); $redis = Snowflake::app()->getRedis();
/** @var Crontab $crontab */
$crontab = swoole_unserialize($redis->get($value)); $crontab = swoole_unserialize($redis->get($value));
$redis->hSet('crontab:wait:execute', $crontab->getName(), $redis->get($value));
$redis->del($value); $redis->del($value);
if (is_object($crontab)) { if (is_object($crontab)) {
$this->channel->push($crontab); $this->channel->push($crontab);
+1
View File
@@ -200,6 +200,7 @@ class Crontab extends BaseObject
public function execute(): void public function execute(): void
{ {
$params = call_user_func($this->handler, $this->params, $this->name); $params = call_user_func($this->handler, $this->params, $this->name);
\redis()->hDel('crontab:wait:execute', $this->getName());
if ($params !== null) { if ($params !== null) {
$name = date('Y_m_d_H_i_s.' . $this->name . '.log'); $name = date('Y_m_d_H_i_s.' . $this->name . '.log');
write(storage($name, '/log/crontab'), serialize($params)); write(storage($name, '/log/crontab'), serialize($params));
+1
View File
@@ -65,6 +65,7 @@ class ZookeeperProcess extends Process
} }
/** /**
* @param string $name * @param string $name
*/ */