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