2021-01-04 11:04:48 +08:00

109 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkLibrary
// | github 代码仓库https://github.com/zoujingli/ThinkLibrary
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace think\admin;
use think\admin\service\ProcessService;
use think\admin\service\QueueService;
use think\App;
/**
* 任务基础类
* Class Queue
* @package think\admin
*/
abstract class Queue
{
/**
* 应用实例
* @var App
*/
protected $app;
/**
* 任务控制服务
* @var QueueService
*/
protected $queue;
/**
* 进程控制服务
* @var ProcessService
*/
protected $process;
/**
* Queue constructor.
* @param App $app
* @param ProcessService $process
*/
public function __construct(App $app, ProcessService $process)
{
$this->app = $app;
$this->process = $process;
}
/**
* 初始化任务数据
* @param QueueService $queue
* @return $this
*/
public function initialize(QueueService $queue): Queue
{
$this->queue = $queue;
return $this;
}
/**
* 执行任务处理内容
* @param array $data
*/
abstract public function execute($data = []);
/**
* 设置任务的进度
* @param null|string $message 进度消息
* @param null|float $progress 进度数值
* @param integer $backline 回退行数
* @return Queue
*/
protected function setQueueProgress(?string $message = null, $progress = null, $backline = 0): Queue
{
$this->queue->progress(2, $message, $progress, $backline);
return $this;
}
/**
* 设置成功的消息
* @param string $message 消息内容
* @throws Exception
*/
protected function setQueueSuccess(string $message): void
{
$this->queue->success($message);
}
/**
* 设置失败的消息
* @param string $message 消息内容
* @throws Exception
*/
protected function setQueueError(string $message): void
{
$this->queue->error($message);
}
}