niucloud-admin/niucloud/app/job/sys/Cronexecute.php
全栈小学生 0e47055ccb v1.0.0-beta.1
2023-04-15 17:12:49 +08:00

65 lines
1.8 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
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的saas管理平台
// +----------------------------------------------------------------------
// | 官方网址https://www.niucloud-admin.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\job\sys;
use app\job\BaseJob;
use app\model\system\Cron;
use app\service\core\cron\CoreCronService;
use think\queue\Job;
/**
* 队列异步调用定时任务
*/
class Cronexecute extends BaseJob
{
public function fire(Job $job, $data)
{
//....这里执行具体的任务
// if ($job->attempts() > 3) {
// //通过这个方法可以检查这个任务已经重试了几次了
// }
//
//
// //如果任务执行成功后 记得删除任务不然这个任务会重复执行直到达到最大重试次数后失败后执行failed方法
// $job->delete();
//
// // 也可以重新发布这个任务
// $job->release($delay ?? 0); //$delay为延迟时间
$res = event($data[ 'event' ], $data['data'] );
//根据结果来判断下一步
$cron_task_model = new CoreCronService();
//定义最新的执行时间或错误
$cron_task_model->after($data);
$job->delete();
}
/**
* 失败后的解决方案或提示
* @param $data
* @return void
*/
public function failed($data){
// ...任务达到最大重试次数后,失败了
}
}