yiisoft / yiisoft/yii2-queue

Incorrect behavior when adding a message to a queue from a job

Open
#305 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status:to be verified
Dominant language
PHP
Stars
1.1k
Forks
285
Avg merge
5d 3h
Merged PRs (30d)
2

Description

What steps will reproduce the problem?

Trying push message to queue from job.


class NotificationJob extends BaseObject implements JobInterface
{
    public function execute($queue)
    {
        $instances = $this->getInstances();
        foreach ($instances as $instance) {
            $queue->push(new SenderJob($instance));
        }
    }
}
$config = [
    'bootstrap' => ['queuePush'],
    'components' => [
        'queuePush' => [
            'class' => \yii\queue\amqp_interop\Queue::class,
            'host' => $rabbit['host'],
            'port' => $rabbit['port'],
            'user' => $rabbit['user'],
            'password' => $rabbit['pass'],
            'driver' => yii\queue\amqp_interop\Queue::ENQUEUE_AMQP_LIB,

            'queueName' => 'push',
        ]
    ],
];

supervisor config


[program:yii-queue-push]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /var/www/project/yii queue-push/listen
autostart=true
autorestart=true
user=www-data
numprocs=10
redirect_stderr=true
stdout_logfile=/var/www/project/scripts/log/yii-queue-push.log

What's expected?

I expect that after the NotificationJob, the queue will get some SenderJob and then start executing them.

What do you get instead?

All SenderJob are executed in the NotificationJob and additionally added to the queue several times.

If you put SenderJob in another queue, where a $instances contains one array element.
The SenderJob will be executed and 3 messages will be added to the queuePushSend, although the SenderJob should not be executed and 1 message should be added to the queuePushSend.

class NotificationJob extends BaseObject implements JobInterface
{
    public function execute($queue)
    {
        $instances = $this->getInstances();
        foreach ($instances as $instance) {
            Yii::$app->queuePushSend->push(new SenderJob($instance));
        }
    }
}
Additional info
Q A
Yii version 2.0.15.1
yii2-queue 2.1.0
PHP version 7.1.24
Operating system ubuntu16.04.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the NotificationJob and SenderJob flow with the yii queue-push/listen entry point and the shown Supervisor configuration. Compare execution from the originating job with delivery through queuePush and queuePushSend, including the case where instances contains one element. Done means the SenderJob is not executed inline and is added to the intended queue exactly once.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, rabbitmq
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.