智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

57 lines
1.8 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace core\job;
use core\util\Queue;
/**
* 任务派遣队列
*/
class Dispatch
{
/**
* 加入队列
* @param $action
* @param array $data
* @param int $secs
* @param string|null $queue_name
* @param bool $is_async
* @return mixed
*/
public static function dispatch($action, array $data = [], int $secs = 0, string $queue_name = null, bool $is_async = true)
{
$class = static::class;//调用主调类
if (env('queue.state', false) && $is_async) {
$queue = Queue::instance()->job($class)->secs($secs);
if (is_array($action)) {
$queue->data(...$action);
} else if (is_string($action)) {
$queue->method($action)->data(...$data);
}
if ($queue_name) {
$queue->setQueueName($queue_name);
}
return $queue->push();
} else {
if($secs == 0){
$class_name = '\\' . $class;
$res = new $class_name();
if (is_array($action)) {
return $res->doJob(...$action);
} else {
return $res->$action(...$data);
}
}
}
}
}