Skip to content

Laravel 5.5 Delay between retries (failed jobs) not working #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vrubiella opened this issue Nov 8, 2017 · 5 comments
Closed

Laravel 5.5 Delay between retries (failed jobs) not working #156

vrubiella opened this issue Nov 8, 2017 · 5 comments

Comments

@vrubiella
Copy link

Hi Vladimir,

When I run this command:

php artisan queue:work rabbitmq --sleep=2 --tries=3 --delay=20 --daemon

Failed jobs are requeued without delay (20s).

Also, when I check attemps() for a job, always returns 1.

this is my queue conf:

        'rabbitmq' => [
            'driver'                => 'rabbitmq',

            'host'                  => env('RABBITMQ_HOST', '127.0.0.1'),
            'port'                  => env('RABBITMQ_PORT', 5672),

            'vhost'                 => env('RABBITMQ_VHOST', '/'),
            'login'                 => env('RABBITMQ_LOGIN', 'guest'),
            'password'              => env('RABBITMQ_PASSWORD', 'guest'),

            'queue'                 => env('RABBITMQ_QUEUE','backend_api_11_jobs'), // name of the default queue,

            'exchange_declare'      => env('RABBITMQ_EXCHANGE_DECLARE', true), // create the exchange if not exists
            'queue_declare_bind'    => env('RABBITMQ_QUEUE_DECLARE_BIND', true), // create the queue if not exists and bind to the exchange

            'queue_params'          => [
                'passive'           => env('RABBITMQ_QUEUE_PASSIVE', false),
                'durable'           => env('RABBITMQ_QUEUE_DURABLE', true),
                'exclusive'         => env('RABBITMQ_QUEUE_EXCLUSIVE', false),
                'auto_delete'       => env('RABBITMQ_QUEUE_AUTODELETE', false),
            ],

            'exchange_params' => [
                'name'        => env('RABBITMQ_EXCHANGE_NAME', null),
                'type'        => env('RABBITMQ_EXCHANGE_TYPE', 'direct'), // more info at http://www.rabbitmq.com/tutorials/amqp-concepts.html
                'passive'     => env('RABBITMQ_EXCHANGE_PASSIVE', false),
                'durable'     => env('RABBITMQ_EXCHANGE_DURABLE', true), // the exchange will survive server restarts
                'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false),
            ],

        ],
@makasim
Copy link
Contributor

makasim commented Nov 8, 2017

you could try this #154. The delay should work there.

The delaying code has already been heavily tested.

@vrubiella
Copy link
Author

vrubiella commented Nov 8, 2017

Hi @makasim , I'm trying your PR.

I just change:

composer.json
"vladimir-yuldashev/laravel-queue-rabbitmq": "dev-amqp-interop",

.env
add new .env : RABBITMQ_DSN=amqp://admin:XXXX@cms-rabbitmq:5672/%2F

If no errors, works fine (ok :D), but when error occurs, failes when try to add job on failed_job table:

Integrity constraint violation: 1048 Column 'queue' cannot be null .

Also, good news is delay between failed jobs works fine!:

[2017-11-08 08:57:25] pre.DEBUG: Processing [App\Jobs\Installation\CopyFilesFromRepoJob][1883] ]
[2017-11-08 08:57:45] pre.DEBUG: Processing [App\Jobs\Installation\CopyFilesFromRepoJob][1883] 

I think the problem is related with $queue attribute in RabbitMQJob.

https://github.com/vyuldashev/laravel-queue-rabbitmq/pull/154/files#diff-2af4187a15d8d89ec1ac5d0ca7b5e993

with this changes, queue attribute is not filled, and this attribute is used on vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php:186
when log failed job in table.

@makasim
Copy link
Contributor

makasim commented Nov 8, 2017

@vrubiella thank you for reporting it. I'll look into it.

@vrubiella
Copy link
Author

vrubiella commented Nov 8, 2017

I confirm you, adding this line on RabbitMQJob constructor, bug was fixed:

$this->queue = $consumer->getQueue()->getQueueName();

    public function __construct(
        Container $container,
        RabbitMQQueue $connection,
        AmqpConsumer $consumer,
        AmqpMessage $message
    ) {
        $this->container = $container;
        $this->connection = $connection;
        $this->consumer = $consumer;
        $this->message = $message;
        $this->queue = $consumer->getQueue()->getQueueName();
    }

@makasim
Copy link
Contributor

makasim commented Nov 8, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants