modify
This commit is contained in:
+5
-1
@@ -7,6 +7,7 @@ namespace Snowflake;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Snowflake\Abstracts\BaseObject;
|
||||
use Snowflake\Process\CrontabProcess;
|
||||
use Swoole\Timer;
|
||||
|
||||
/**
|
||||
@@ -185,7 +186,7 @@ class Crontab extends BaseObject
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(): void
|
||||
public function execute(CrontabProcess $process): void
|
||||
{
|
||||
try {
|
||||
var_dump('execute');
|
||||
@@ -193,6 +194,9 @@ class Crontab extends BaseObject
|
||||
$this->execute_number += 1;
|
||||
if ($this->execute_number >= $this->max_execute_number) {
|
||||
$this->clearTimer();
|
||||
$process->clear($this->getName());
|
||||
} else if (!$this->isLoop()) {
|
||||
$process->clear($this->getName());
|
||||
}
|
||||
} catch (\Throwable $throwable) {
|
||||
$this->addError($throwable->getMessage());
|
||||
|
||||
@@ -56,14 +56,13 @@ class CrontabProcess extends Process
|
||||
{
|
||||
call_user_func(match ($content['action']) {
|
||||
'clear' => function ($content) {
|
||||
if (!isset($this->names[$content['name']])) {
|
||||
return;
|
||||
}
|
||||
$this->names[$content['name']]->clearTimer();
|
||||
$this->clear($content['name']);
|
||||
},
|
||||
'clearAll' => function () {
|
||||
foreach ($this->names as $name => $crontab) {
|
||||
$crontab->clearTimer();
|
||||
|
||||
unset($this->names[$name], $crontab);
|
||||
}
|
||||
},
|
||||
default => function () {
|
||||
@@ -73,6 +72,18 @@ class CrontabProcess extends Process
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function clear(string $name)
|
||||
{
|
||||
if (!isset($this->names[$name])) {
|
||||
return;
|
||||
}
|
||||
$this->names[$name]->clearTimer();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $content
|
||||
*/
|
||||
@@ -82,7 +93,7 @@ class CrontabProcess extends Process
|
||||
$content = unserialize($content);
|
||||
$runTicker = function (Crontab $crontab) {
|
||||
var_dump(get_called_class());
|
||||
$crontab->execute();
|
||||
$crontab->execute($this);
|
||||
};
|
||||
$timer = $content->getTickTime() * 1000;
|
||||
var_dump($timer);
|
||||
|
||||
Reference in New Issue
Block a user