在YII2中如何在控制器中运行特定的队列作业ID?

问题描述 投票:0回答:1

我使用 yiisoft /yii2-queue 扩展来进行队列 https://github.com/yiisoft/yii2-queue 我想从队列表中获取特定的作业 ID 并运行该作业 ID。

php yii2 queue
1个回答
0
投票

它本身不支持。作为解决方法,您可以尝试使用内部

Command.actionExec()
,具有以下文档块和签名:

/**
 * Executes a job.
 * The command is internal, and used to isolate a job execution. Manual usage is not provided.
 *
 * @param string|null $id of a message
 * @param int $ttr time to reserve
 * @param int $attempt number
 * @param int $pid of a worker
 * @return int exit code
 * @internal It is used with isolate mode.
 */
public function actionExec($id, $ttr, $attempt, $pid)  

所以,尝试以这种格式使用它:

$ php yii queue/exec "id" "ttr" "attempt" "pid"

[

php
yii
应该是 shell 或可执行文件的路径。]

有关如何在代码中使用它的说明,请查看 Command.handleMessage():

$cmd = [
    $this->phpBinary,
    $_SERVER['SCRIPT_FILENAME'],
    $this->uniqueId . '/exec',
    $id,
    $ttr,
    $attempt,
    $this->queue->getWorkerPid() ?: 0,
];

foreach ($this->getPassedOptions() as $name) {
    if (in_array($name, $this->options('exec'), true)) {
        $cmd[] = '--' . $name . '=' . $this->$name;
    }
}
if (!in_array('color', $this->getPassedOptions(), true)) {
    $cmd[] = '--color=' . $this->isColorEnabled();
}

$process = new Process($cmd, null, null, $message, $ttr);
© www.soinside.com 2019 - 2024. All rights reserved.