改名
This commit is contained in:
@@ -28,7 +28,6 @@ use Annotation\Annotation as SAnnotation;
|
|||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Snowflake\Async;
|
use Snowflake\Async;
|
||||||
use Snowflake\Cache\Redis;
|
use Snowflake\Cache\Redis;
|
||||||
use Snowflake\Crontab;
|
|
||||||
use Snowflake\Di\Service;
|
use Snowflake\Di\Service;
|
||||||
use Snowflake\Error\ErrorHandler;
|
use Snowflake\Error\ErrorHandler;
|
||||||
use Snowflake\Error\Logger;
|
use Snowflake\Error\Logger;
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Snowflake\Abstracts;
|
||||||
|
|
||||||
|
|
||||||
|
use Snowflake\Snowflake;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Crontab
|
||||||
|
* @package Snowflake\Abstracts
|
||||||
|
*/
|
||||||
|
class Crontab extends Component
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Snowflake\Crontab $crontab
|
||||||
|
* @param $executeTime
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function dispatch(\Snowflake\Crontab $crontab, int $executeTime)
|
||||||
|
{
|
||||||
|
$redis = Snowflake::app()->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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -17,7 +17,6 @@ use HttpServer\Server;
|
|||||||
use Kafka\Producer;
|
use Kafka\Producer;
|
||||||
use Snowflake\Async;
|
use Snowflake\Async;
|
||||||
use Snowflake\Cache\Redis;
|
use Snowflake\Cache\Redis;
|
||||||
use Snowflake\Crontab;
|
|
||||||
use Snowflake\Error\Logger;
|
use Snowflake\Error\Logger;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
use Snowflake\Jwt\Jwt;
|
use Snowflake\Jwt\Jwt;
|
||||||
|
|||||||
+58
-15
@@ -6,13 +6,13 @@ namespace Snowflake;
|
|||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Snowflake\Abstracts\Component;
|
use Snowflake\Abstracts\BaseObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Async
|
* Class Async
|
||||||
* @package Snowflake
|
* @package Snowflake
|
||||||
*/
|
*/
|
||||||
class Crontab extends Component
|
class Crontab extends BaseObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@@ -36,6 +36,62 @@ class Crontab extends Component
|
|||||||
|
|
||||||
private int $execute_number = 0;
|
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
|
* @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
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user