This commit is contained in:
as2252258@163.com
2021-03-26 01:47:24 +08:00
parent 265afa6cb8
commit 075472df92
2 changed files with 20 additions and 33 deletions
+14 -21
View File
@@ -41,12 +41,22 @@ class Consumer extends Process
*/ */
public function popChannel() public function popChannel()
{ {
/** @var Crontab $crontab */
$crontab = $this->channel->pop(-1); $crontab = $this->channel->pop(-1);
go(function () use ($crontab) { go(function () use ($crontab) {
$this->dispatch($crontab); try {
$crontab->increment()->execute();
if ($crontab->getExecuteNumber() < $crontab->getMaxExecuteNumber()) {
Consumer::addTask($crontab);
} else if ($crontab->isLoop()) {
Consumer::addTask($crontab);
}
} catch (\Throwable $throwable) {
$this->application->addError($throwable->getMessage());
} finally {
fire(Event::SYSTEM_RESOURCE_RELEASES);
}
}); });
$this->popChannel(); $this->popChannel();
} }
@@ -76,28 +86,11 @@ class Consumer extends Process
} }
/**
* @param Crontab $value
* @throws Exception
*/
private function dispatch(Crontab $value)
{
$value->increment()->execute();
if ($value->getExecuteNumber() < $value->getMaxExecuteNumber()) {
$this->addTask($value);
} else if ($value->isLoop()) {
$this->addTask($value);
}
var_dump($value);
fire(Event::SYSTEM_RESOURCE_RELEASES);
}
/** /**
* @param Crontab $crontab * @param Crontab $crontab
* @throws Exception * @throws Exception
*/ */
private function addTask(Crontab $crontab) private static function addTask(Crontab $crontab)
{ {
$redis = Snowflake::app()->getRedis(); $redis = Snowflake::app()->getRedis();
+6 -12
View File
@@ -181,10 +181,10 @@ class Crontab extends BaseObject
} }
/** /**
* *
* @throws Exception * @throws Exception
*/ */
public function clearTimer() public function clearTimer()
{ {
$this->warning('crontab timer clear.'); $this->warning('crontab timer clear.');
@@ -199,14 +199,8 @@ class Crontab extends BaseObject
*/ */
public function execute(): void public function execute(): void
{ {
try { var_dump(call_user_func($this->handler, $this->params, $this->name));
// $result = call_user_func($this->handler, $this->params, $this->name);
var_dump(($this->handler)($this->params, $this->name));
} catch (\Throwable $throwable) {
$this->addError($throwable->getMessage());
} finally {
fire(Event::SYSTEM_RESOURCE_RELEASES);
}
} }