更新和重新排队长期运行的Laravel作业

时间:2017-08-27 23:23:47

标签: php laravel laravel-5 queue laravel-5.4

我有一些Laravel作业需要等待很长时间(15-60秒)才能让第三方API完成任务才能继续。在轮询完成作业时保持线程锁定是非常浪费的。

有没有办法更新作业的有效负载/状态并重新排队,以便在完成其他一些作业后,作业可以恢复并再次轮询?

我在想:

// In a handling method within the job.
$this->state = 'waitingForSomeTask';

// Save the payload / state of this job (this is the "missing" method)
$this->save();

// Put the task back on the queue with a five second delay
$this->release(5);

从这里开始,下一次作业处理程序运行时,它可以从中断处取出(作业变量已被转移) - 检查任务是否完成,如果是,则继续;如果没有,它会再次重新安排工作。

我在官方文档或其他地方的任何地方都没有看到过这种情况,所以有没有更好/更“Laravel-esque”的方法来做到这一点?

0 个答案:

没有答案
相关问题