改名
This commit is contained in:
+39
-13
@@ -15,7 +15,7 @@ use Swoole\Timer;
|
|||||||
* Class Async
|
* Class Async
|
||||||
* @package Snowflake
|
* @package Snowflake
|
||||||
*/
|
*/
|
||||||
class Crontab extends BaseObject
|
abstract class Crontab extends BaseObject
|
||||||
{
|
{
|
||||||
|
|
||||||
const WAIT_END = 'crontab:wait:execute';
|
const WAIT_END = 'crontab:wait:execute';
|
||||||
@@ -236,6 +236,12 @@ class Crontab extends BaseObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
abstract public function process(): void;
|
||||||
|
|
||||||
|
abstract public function max_execute(): void;
|
||||||
|
abstract public function isStop(): bool;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@@ -250,7 +256,7 @@ class Crontab extends BaseObject
|
|||||||
|
|
||||||
array_push($this->params, $this->name);
|
array_push($this->params, $this->name);
|
||||||
|
|
||||||
$params = call_user_func($this->handler, ...$this->params);
|
$params = call_user_func([$this, 'process'], ...$this->params);
|
||||||
$redis->hDel(self::WAIT_END, $name_md5);
|
$redis->hDel(self::WAIT_END, $name_md5);
|
||||||
if ($params === null) {
|
if ($params === null) {
|
||||||
return;
|
return;
|
||||||
@@ -265,25 +271,45 @@ class Crontab extends BaseObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isExit(): bool
|
||||||
|
{
|
||||||
|
if ($this->_stop === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!$this->isLoop) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function isMaxExecute(): bool
|
||||||
|
{
|
||||||
|
if ($this->max_execute_number !== -1) {
|
||||||
|
return $this->execute_number >= $this->max_execute_number;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function after(): void
|
private function after(): void
|
||||||
{
|
{
|
||||||
if ($this->_stop === true) {
|
if ($this->isExit()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($this->isLoop()) {
|
if ($this->isMaxExecute()) {
|
||||||
$this->recover();
|
call_user_func([$this, 'max_execute'], ...$this->params);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ($this->max_execute_number == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ($this->getExecuteNumber() < $this->getMaxExecuteNumber()) {
|
|
||||||
$this->recover();
|
|
||||||
} else {
|
} else {
|
||||||
call_user_func($this->_max_execute_handler, ...$this->params);
|
$this->recover();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Snowflake\Crontab;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DefaultCrontab
|
||||||
|
* @package Snowflake\Crontab
|
||||||
|
*/
|
||||||
|
class DefaultCrontab extends Crontab
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isStop(): bool
|
||||||
|
{
|
||||||
|
// TODO: Implement isStop() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function process(): void
|
||||||
|
{
|
||||||
|
// TODO: Implement process() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function max_execute(): void
|
||||||
|
{
|
||||||
|
// TODO: Implement max_execute() method.
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user