diff --git a/System/Abstracts/BaseApplication.php b/System/Abstracts/BaseApplication.php index 0cf66de4..ff673492 100644 --- a/System/Abstracts/BaseApplication.php +++ b/System/Abstracts/BaseApplication.php @@ -28,7 +28,6 @@ use Annotation\Annotation as SAnnotation; use ReflectionException; use Snowflake\Async; use Snowflake\Cache\Redis; -use Snowflake\Crontab; use Snowflake\Di\Service; use Snowflake\Error\ErrorHandler; use Snowflake\Error\Logger; diff --git a/System/Abstracts/Crontab.php b/System/Abstracts/Crontab.php new file mode 100644 index 00000000..ca2a2f2c --- /dev/null +++ b/System/Abstracts/Crontab.php @@ -0,0 +1,65 @@ +getRedis(); + + $redis->zAdd('system:crontab', (string)$executeTime, serialize($crontab)); + } + + + /** + * @param string $name + * @throws Exception + */ + public function clear(string $name) + { + $redis = Snowflake::app()->getRedis(); + + $data = $redis->zRevRange('system:crontab', '0', '-1'); + + foreach ($data as $datum) { + /** @var \Snowflake\Crontab $crontab */ + $crontab = unserialize($datum); + if ($crontab->getName() == $name) { + $redis->zRem('system:crontab', $datum); + break; + } + } + + } + + + /** + * @throws Exception + */ + public function clearAll() + { + $redis = Snowflake::app()->getRedis(); + + $redis->zRemRangeByRank('system:crontab', '0', '-1'); + } + + +} diff --git a/System/Abstracts/TraitApplication.php b/System/Abstracts/TraitApplication.php index c2964260..51a12069 100644 --- a/System/Abstracts/TraitApplication.php +++ b/System/Abstracts/TraitApplication.php @@ -17,7 +17,6 @@ use HttpServer\Server; use Kafka\Producer; use Snowflake\Async; use Snowflake\Cache\Redis; -use Snowflake\Crontab; use Snowflake\Error\Logger; use Snowflake\Event; use Snowflake\Jwt\Jwt; diff --git a/System/Crontab.php b/System/Crontab.php index fbb7ae77..d0d4f60e 100644 --- a/System/Crontab.php +++ b/System/Crontab.php @@ -6,13 +6,13 @@ namespace Snowflake; use Closure; use Exception; -use Snowflake\Abstracts\Component; +use Snowflake\Abstracts\BaseObject; /** * Class Async * @package Snowflake */ -class Crontab extends Component +class Crontab extends BaseObject { @@ -36,6 +36,62 @@ class Crontab extends Component private int $execute_number = 0; + /** + * @return array|Closure + */ + public function getHandler(): array|Closure + { + return $this->handler; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return mixed + */ + public function getParams(): mixed + { + return $this->params; + } + + /** + * @return int + */ + public function getTickTime(): int + { + return $this->tickTime; + } + + /** + * @return bool + */ + public function isLoop(): bool + { + return $this->isLoop; + } + + /** + * @return int + */ + public function getMaxExecuteNumber(): int + { + return $this->max_execute_number; + } + + /** + * @return int + */ + public function getExecuteNumber(): int + { + return $this->execute_number; + } + /** * @param array|Closure $handler @@ -94,19 +150,6 @@ class Crontab extends Component } - /** - * @throws Exception - */ - public function dispatch() - { - $redis = Snowflake::app()->getRedis(); - - $executeTime = $this->tickTime + time(); - - $redis->zAdd('system:crontab', (string)$executeTime, serialize($this)); - } - - /** * @throws Exception */