TaskChangedToProcessing.php 1.7 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 任务自动开锁
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Jobs\Gift
 * @package   App\Jobs\Gift
 * @author    Richer <yangzi1028@163.com>
 * @date      2022年10月27日15:29:08
 * @copyright 2022-2022 Richer (http://www.umu888.com)
 * @license   http://www.Richer.com License
 * @link      http://www.Richer.com
 */
namespace App\Jobs\Score;

use App\Jobs\BaseJob;
use App\Models\Score\Task;

/**
 * Class TaskChangedToProcessing
 *
 * @package App\Jobs\Score
 */
class TaskChangedToProcessing extends BaseJob
{
    /**
     * Create a new job instance.
     *
     * @param Task $model
     * @param integer $delay 延迟
     */
    public function __construct(Task $model, int $delay)
    {
        $this->desc  = '评分任务自动开始!';
        // 执行
        parent::__construct($model, $delay);
    }

    /**
     * 定义这个任务类具体的执行逻辑
     * 当队列处理器从队列中取出任务时,会调用 handle() 方法
     * Execute the job.
     *
     * @return void
     * @throws \Throwable
     */
    public function handle()
    {
        // 记录日志
        $this->log($this->desc, 'begin');

        if ($this->attempts() > 1) {
            $this->log('尝试次数过多');
        } else {
            $model = $this->model;
            if ($model->status !== Task::NOT_STARTED) {
                return;
            }

        }
        $this->log($this->desc, 'end');
    }
}