This commit is contained in:
as2252258@163.com
2021-03-20 03:51:07 +08:00
parent 491d4bc50a
commit 95cc43ab39
2 changed files with 8 additions and 16 deletions
+2
View File
@@ -189,6 +189,8 @@ class Crontab extends BaseObject
public function execute(CrontabProcess $process): void public function execute(CrontabProcess $process): void
{ {
try { try {
$this->warning('execute crontab.');
call_user_func($this->handler, $this->params); call_user_func($this->handler, $this->params);
$this->execute_number += 1; $this->execute_number += 1;
if ($this->execute_number >= $this->max_execute_number) { if ($this->execute_number >= $this->max_execute_number) {
+6 -16
View File
@@ -84,11 +84,8 @@ class CrontabProcess extends Process
$this->clear($content['name']); $this->clear($content['name']);
}, },
'clearAll' => function () { 'clearAll' => function () {
foreach ($this->names as $name => $crontab) { $this->names = [];
$crontab->clearTimer(); Timer::clearAll();
unset($this->names[$name], $crontab);
}
}, },
default => function () { default => function () {
$this->application->error('unknown action'); $this->application->error('unknown action');
@@ -105,7 +102,7 @@ class CrontabProcess extends Process
if (!isset($this->names[$name])) { if (!isset($this->names[$name])) {
return; return;
} }
$this->names[$name]->clearTimer(); Timer::exists($this->names[$name]) && Timer::clear($this->names[$name]);
unset($this->names[$name]); unset($this->names[$name]);
} }
@@ -117,19 +114,12 @@ class CrontabProcess extends Process
{ {
/** @var Crontab $content */ /** @var Crontab $content */
$content = unserialize($content); $content = unserialize($content);
$runTicker = function () use ($content) { $runTicker = [$content->getTickTime() * 1000, [$content, 'execute']];
var_dump('execute crontab ' . date('Y-m-d H:i:s'));
// $content->execute($this);
};
var_dump($content->getTickTime());
var_dump($content->isLoop());
if ($content->isLoop()) { if ($content->isLoop()) {
$worker = Timer::tick($content->getTickTime() * 1000, $runTicker); $this->names[$content->getName()] = Timer::tick(...$runTicker);
} else { } else {
$worker = Timer::after($content->getTickTime() * 1000, $runTicker); $this->names[$content->getName()] = Timer::after(...$runTicker);
} }
// $content->setTimerId($worker);
// $this->names[$content->getName()] = $content;
} }