Skip to content
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

How do I use retry? #350

Open
wxxiong6 opened this issue Sep 5, 2019 · 2 comments
Open

How do I use retry? #350

wxxiong6 opened this issue Sep 5, 2019 · 2 comments
Labels
status:to be verified Needs to be reproduced and validated.

Comments

@wxxiong6
Copy link

wxxiong6 commented Sep 5, 2019

How do I use retry?

Q A
Yii version 2.0.15.1
PHP version 7.2.5
Operating system linux
<?php
namespace backend\job;

use yii\queue\RetryableJobInterface;

class TestPush implements RetryableJobInterface
{
    public $jobLogId;
    
    public function execute($queue)
    {
        var_dump($queue->attempts, $queue->ttr);
        echo '123123213213' , "\n";
        throw new \Exception(date("Y-m-d H:i:s"));
    }
    
    public function getTtr()
    {
        return 30;
    }
    
    public function canRetry($attempt, $error)
    {
        echo $attempt. " ============ canRetry \n";
        return true;
    }
}

output

2019-09-05 09:36:22 [5d70615ba9a845.54703703] backend\job\TestPush (attempt: 1) - Started
/var/www/html/privateFund/trunk/backend/job/TestPush.php:12:
int(1)
/var/www/html/privateFund/trunk/backend/job/TestPush.php:12:
int(300)
123123213213
1 ============ canRetry
2019-09-05 09:36:22 [5d70615ba9a845.54703703] backend\job\TestPush (attempt: 1) - Error (0.081 s)
> Exception: 2019-09-05 09:36:22

1 ============ canRetry
The attempt is always 1

@rob006
Copy link

rob006 commented Sep 5, 2019

Next try should increment $attempt. Can you share logs of two sequential tries of the same job?

@yiisoft yiisoft deleted a comment from yii-bot Sep 5, 2019
@wxxiong6
Copy link
Author

wxxiong6 commented Sep 6, 2019

I used amqp deivers .
The driver does not support retry.
see yii2-queue/src/drivers/amqp/Queue.php:63

    public function listen()
    {
        $this->open();
        $callback = function (AMQPMessage $payload) {
            $id = $payload->get('message_id');
            list($ttr, $message) = explode(';', $payload->body, 2);
            if ($this->handleMessage($id, $message, $ttr, 1)) {
                $payload->delivery_info['channel']->basic_ack($payload->delivery_info['delivery_tag']);
            }
        };
        $this->channel->basic_qos(null, 1, null);
        $this->channel->basic_consume($this->queueName, '', false, false, false, false, $callback);
        while (count($this->channel->callbacks)) {
            $this->channel->wait();
        }
    }

amqp_interop drivers can use retry but need to upgrade PHP version to 7.1.3.

@bizley bizley added status:to be verified Needs to be reproduced and validated. and removed status:need more info labels Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated.
Projects
None yet
Development

No branches or pull requests

4 participants