简体   繁体   English

Laravel SQS队列->延迟的作业失败

[英]Laravel SQS Queue -> delayed jobs fail

I am trying to delay a job in Laravel that is dispatched to a AWS SQS queue. 我正在尝试延迟Laravel中分配给AWS SQS队列的作业。 Standard jobs that are not delayed run fine on that queue but as soon as I delay something, it crashes. 没有延迟的标准作业可以在该队列上正常运行,但是一旦我延迟一些作业,它就会崩溃。 I first tried: 我首先尝试:

$awsgatewayjob = new \App\Jobs\DispatchAwsGatewayJob();
$this->dispatch($awsgatewayjob)->delay(now()->addMinutes(1));

This gives error: Symfony \\ Component \\ Debug \\ Exception \\ FatalThrowableError (E_ERROR) Call to a member function delay() on string 这会产生错误: Symfony \\组件\\调试\\异常\\ FatalThrowableError(E_ERROR)对字符串的成员函数delay()的调用

Next, I tried to do it using the style Laravel explains in the manual: 接下来,我尝试使用手册中Laravel解释的样式进行操作:

DispatchAwsGatewayJob::dispatch()->delay(now()->addMinutes(1));

And this gives error: 这给出了错误:

Symfony \\ Component \\ Debug \\ Exception \\ FatalThrowableError (E_ERROR) Call to undefined method Maqe\\LaravelSqsFifo\\SqsFifoQueue::getSeconds() Symfony \\组件\\调试\\异常\\ FatalThrowableError(E_ERROR)调用未定义的方法Maqe \\ LaravelSqsFifo \\ SqsFifoQueue :: getSeconds()

I googled the last error and I am happy to report I am not the only one that experienced that error: https://github.com/maqe/laravel-sqs-fifo/issues/7 我用Google搜索了最后一个错误,我很高兴地报告我不是唯一一个遇到该错误的人: https : //github.com/maqe/laravel-sqs-fifo/issues/7

Anyway, I don't get it. 无论如何,我不明白。 I am running on Laravel 5.5 and I updated all my packages with composer update to make sure I wasn't using an outdated package. 我在Laravel 5.5上运行,并且用composer update更新了所有软件包,以确保我没有使用过时的软件包。

Any ideas? 有任何想法吗?

Here is the (redacted) code for the job: 这是作业的(已编辑)代码:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

use Auth;
use Session;

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Alert;


class DispatchAwsGatewayJob implements ShouldQueue
{

  private $method;
  private $rest_method;
  private $data;

  use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

  /**
  * Create a new job instance.
  *
  * @return void
  */
  public function __construct($method, $rest_method, $data)
  {
    $this->method = $method;
    $this->rest_method = $rest_method;
    $this->data = $data;

  }

  /**
  * Execute the job.
  *
  * @return void
  */
  public function handle()
  {
    $curl = curl_init();

    // some more stuff here to config $curl

    $result = curl_exec($curl);
    curl_close($curl);
  }
}

Here is the full error log: 这是完整的错误日志:

Symfony\\Component\\Debug\\Exception\\FatalThrowableError thrown with message "Call to undefined method Maqe\\LaravelSqsFifo\\SqsFifoQueue::getSeconds()" 出现消息“调用未定义的方法Maqe \\ LaravelSqsFifo \\ SqsFifoQueue :: getSeconds()”引发的Symfony \\ Component \\ Debug \\ Exception \\ FatalThrowableError

Stacktrace: 堆栈跟踪:

0 Symfony\\Component\\Debug\\Exception\\FatalThrowableError in /var/www/sparkwebsite/vendor/maqe/laravel-sqs-fifo/src/SqsFifoQueue.php:42 /var/www/sparkwebsite/vendor/maqe/laravel-sqs-fifo/src/SqsFifoQueue.php:42中的0 Symfony \\ Component \\ Debug \\ Exception \\ FatalThrowableError

This is the complete stacktrace. 这是完整的堆栈跟踪。 I am now using a standard queue and everything runs fine! 我现在正在使用标准队列,并且一切运行正常!

Your specific error is because the getSeconds() method was removed in Laravel 5.4. 您的特定错误是因为在Laravel 5.4中删除了getSeconds()方法。 That package has an update in the master branch to add 5.4+ compatibility, but there is no tagged release with that code, so you'd have to update your composer.json file to point to dev-master . 该软件包在master分支中进行了更新,以增加5.4+兼容性,但是该代码没有带标签的发行版,因此您必须更新composer.json文件以指向dev-master

However, there is a bigger issue at play here. 但是,这里有一个更大的问题。 While the package you're using attempts to support the delay functionality, this isn't actually correct. 当您使用的程序包尝试支持delay功能时,这实际上是不正确的。

SQS FIFO queues do not support per-message delays. SQS FIFO队列不支持每个消息的延迟。 They only support per-queue delays, meaning you must define your queue in AWS with a delay (max 15 minutes), as seen in the screenshot below. 它们仅支持按队列延迟,这意味着您必须在AWS中定义延迟(最多15分钟),如下面的屏幕快照所示。 Attempting to set a delay on a message sent to a queue that is not defined with a delay will not have any effect. 尝试对发送到未使用延迟定义的队列的消息设置延迟不会有任何效果。

延迟概述的SQS设置

So, if you have some jobs that don't use a delay and some jobs that do use a delay, you would need to create at least two queues: one without a delay defined and one with a delay defined. 因此,如果您有一些不使用延迟的作业,而某些确实使用了延迟的作业,则需要至少创建两个队列:一个未定义延迟,一个已定义延迟。 Then, instead of using the delay() method, you would have to use the onQueue() method to send your job to the queue defined with a delay. 然后,您不必使用delay()方法,而必须使用onQueue()方法将您的作业发送到延迟定义的队列中。

Full disclosure: I have also created a Laravel package for handling SQS FIFO queues ( shiftonelabs/laravel-sqs-fifo-queue ). 全面披露:我还创建了一个Laravel包来处理SQS FIFO队列( shiftonelabs / laravel-sqs-fifo-queue )。 Because of the per-message delay restriction on FIFO queues, my package throws an exception when the attempt is made ( BadMethodCallException('FIFO queues do not support per-message delays.') ). 由于对FIFO队列的每个消息延迟有限制,因此我的程序包在尝试时会引发异常( BadMethodCallException('FIFO queues do not support per-message delays.') )。

My package also supports the ability to specify other FIFO specific values, such as the message group id and the deduplication id. 我的软件包还支持指定其他FIFO特定值的功能,例如消息组ID和重复数据删除ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM