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