mirror of
https://gitee.com/niucloud-team/niucloud-admin.git
synced 2025-12-14 11:42:48 +00:00
58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?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);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|