This commit is contained in:
2021-03-19 19:16:12 +08:00
parent 8d5a66e16b
commit 88061f5f3d
4 changed files with 123 additions and 17 deletions
+58 -15
View File
@@ -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
*/