D
D
Dmitry Demenkov2019-04-02 11:20:14
symfony
Dmitry Demenkov, 2019-04-02 11:20:14

Problem with updating data in Symfony and message queue, how to solve?

There is a project on Symfony 4 with a RabbitMq message queue.
Consumer is running and listening to the queue, if a message has arrived, then the command is launched.
Here is a code example from one command:

/** @var Account $account */
        $account = $this->container->get('doctrine')->getRepository(Account::class)->find($account_id);
        if ($account) {
            echo "account=".$account->getUsername()." active=".$account->getActive().PHP_EOL;
            if ($account->getActive()) {

It checks that the account is active, and then the code is executed.
After executing the code, there should be a time delay, this is how it is calculated:
$count_all_account = count($this->container->get('doctrine')->getRepository(Account::class)->findBy(['active' => true]));
        $second = (int)(40 / $count_all_account);

So the problem is that if the account has become inactive, then in the first part of the code, the method
$account->getActive()
returns True,
and in the second part of the code, where the number of active accounts is selected, this account is already inactive.
If you restart Consumer, then everything becomes correct.
How to solve the problem?
Maybe Symfony somehow caches this data?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question