$mineCrontabManage
$mineCrontabManage : \Mine\Crontab\MineCrontabManage
$mineCrontabManage : \Mine\Crontab\MineCrontabManage
dispatch(\Mine\Crontab\MineCrontab $crontab)
\Mine\Crontab\MineCrontab | $crontab |
executeOnce(\Mine\Crontab\MineCrontab $crontab)
执行一次
\Mine\Crontab\MineCrontab | $crontab |
<?php
/**
* MineAdmin is committed to providing solutions for quickly building web applications
* Please view the LICENSE file that was distributed with this source code,
* For the full copyright and license information.
* Thank you very much for using MineAdmin.
*
* @Author X.Mo<root@imoi.cn>
* @Link https://gitee.com/xmo/MineAdmin
*/
declare(strict_types=1);
namespace Mine\Crontab;
use Carbon\Carbon;
use Hyperf\Di\Annotation\Inject;
class MineCrontabStrategy
{
/**
* @Inject
* @var MineCrontabManage
*/
protected $mineCrontabManage;
/**
* @Inject
* @var MineExecutor
*/
protected $executor;
/**
* @param MineCrontab $crontab
*/
public function dispatch(MineCrontab $crontab)
{
co(function() use($crontab) {
if ($crontab->getExecuteTime() instanceof Carbon) {
$wait = $crontab->getExecuteTime()->getTimestamp() - time();
$wait > 0 && \Swoole\Coroutine::sleep($wait);
$this->executor->execute($crontab);
}
});
}
/**
* 执行一次
* @param MineCrontab $crontab
*/
public function executeOnce(MineCrontab $crontab)
{
co(function() use($crontab) {
$this->executor->execute($crontab);
});
}
}