laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

artisan queue:retry all doesn't work

Open llioor opened this issue 5 years ago • 11 comments

"jenssegers/mongodb": "^3.4"

artisan queue:retry all Does not find any failed jobs even when there are some present. Error: No failed job matches the given ID [].

llioor avatar Jul 11 '18 09:07 llioor

Having this same issue. Will try to attach as much details as possible.

php-mongodb version is 1.5.1 composer.json "jenssegers/mongodb": "^3.4" From composer.lock mongodb/mongodb 1.4.2 MongoDB server version is 4.0.0

php artisan queue:failed A cell must be a TableCell, a scalar or an object implementing __toString, array given.

php artisan queue:retry all Unable to find failed job with ID []. Unable to find failed job with ID []. Unable to find failed job with ID [].

I can provide exceptions as well if needed. Another interesting thing to note is that I'm using RabbitMQ for my queue (Only use MongoDB for failed jobs). And in my bootstrap/app.php (I should mention that I use Lumen as well), I have the following:

$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class); $app->register(Jenssegers\Mongodb\MongodbQueueServiceProvider::class); $app->register(VladimirYuldashev\LaravelQueueRabbitMQ\LaravelQueueRabbitMQServiceProvider::class);

$app->withEloquent();

If I put the RabbitMQ ServiceProvider before the other two, then RabbitMQ stops working in Lumen. Not sure if I need the MongodbQueueServiceProvider to make the failed jobs work though. Currently it can add failed jobs, but not process them.

Since I have to release soon, I will go back to MySQL temporarily, but would very much appreciate help with this issue. I'll provide help if necessary to fix this bug.

jra89 avatar Aug 08 '18 13:08 jra89

did you find any solution to this i have the same problem

hazeem1991 avatar Jun 17 '19 12:06 hazeem1991

We have same issue with Laravel 5.8 & jenssegers/mongodb 3.5.1.

nicohell avatar Jun 19 '19 12:06 nicohell

I'm seeing the same issue, this is with the custom service provider in place. The full stack trace is:

[2019-07-22 23:43:34] local.ERROR: A cell must be a TableCell, a scalar or an object implementing __toString, array given. {"exception":"[object] (Symfony\\Component\\Console\\Exception\\InvalidArgumentException(code: 0): A cell must be a TableCell, a scalar or an object implementing __toString, array given. at /usr/src/app/vendor/symfony/console/Helper/Table.php:581)
[stacktrace]
#0 /usr/src/app/vendor/symfony/console/Helper/Table.php(521): Symfony\\Component\\Console\\Helper\\Table->fillNextRows(Array, 2)
#1 /usr/src/app/vendor/symfony/console/Helper/Table.php(345): Symfony\\Component\\Console\\Helper\\Table->buildTableRows(Array)
#2 /usr/src/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(417): Symfony\\Component\\Console\\Helper\\Table->render()
#3 /usr/src/app/vendor/laravel/framework/src/Illuminate/Queue/Console/ListFailedCommand.php(116): Illuminate\\Console\\Command->table(Array, Array)
#4 /usr/src/app/vendor/laravel/framework/src/Illuminate/Queue/Console/ListFailedCommand.php(42): Illuminate\\Queue\\Console\\ListFailedCommand->displayFailedJobs(Array)
#5 [internal function]: Illuminate\\Queue\\Console\\ListFailedCommand->handle()
#6 /usr/src/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#7 /usr/src/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#8 /usr/src/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#9 /usr/src/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(572): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#10 /usr/src/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\\Container\\Container->call(Array)
#11 /usr/src/app/vendor/symfony/console/Command/Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#12 /usr/src/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#13 /usr/src/app/vendor/symfony/console/Application.php(901): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#14 /usr/src/app/vendor/symfony/console/Application.php(262): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\ListFailedCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#15 /usr/src/app/vendor/symfony/console/Application.php(145): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 /usr/src/app/vendor/laravel/framework/src/Illuminate/Console/Application.php(89): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 /usr/src/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /usr/src/app/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 {main}
"}

Using Laravel 5.7

Rodeoclash avatar Jul 22 '19 23:07 Rodeoclash

Exploring this a bit more. This may be because we had failed jobs lodged before we had implemented the custom service provider. We'll try clearing our existing failed jobs and see if new failed jobs that have been lodged with the custom service provider are able to be replayed. If so, I'll report back and I think you'll be able to close this ticket.

Rodeoclash avatar Jul 22 '19 23:07 Rodeoclash

@Rodeoclash I think the issue is because failed_at in mongo is not anymore a timestamp, but a carbon object: "failed_at" : { "date" : "2019-08-02 14:59:39.645173", "timezone_type" : 3, "timezone" : "UTC" } When he should be timestamp : "failed_at" : 1548428034

In laravel it works like a charm, but not in Lumen, I think the problem would start from here vendor/jenssegers/mongodb/src/Jenssegers/Mongodb/MongodbQueueServiceProvider.php Because the MongoFailedJobProvider@log save as timestamp the failed_at date, only the mysql [(else) from MongodbQueueServiceProvider@registerFailedJobServices] is saving him as Carbon

ionutraducanu avatar Aug 02 '19 15:08 ionutraducanu

Experiencing the same issue here with Lumen 6.0 and jenssegers/mongodb 3.6

@ionutraducanu is correct, this is due to the failed_at timestamp.

It is probably better to resolve this by changing how we are saving the failed_at field, but I was able to patch the commands for now by implementing a custom MongoFailedJobProvider which overrides the all() method.

I can confirm after implementing this, all artisan queue commands work as expected.

class MongoFailedJobProvider extends \Jenssegers\Mongodb\Queue\Failed\MongoFailedJobProvider
{
    /**
     * Get a list of all of the failed jobs.
     * @return object[]
     */
    public function all()
    {
        $all = $this->getTable()->orderBy('_id', 'desc')->get()->all();

        $all = array_map(function ($job) {
            $job['id'] = (string)$job['_id'];
            if (isset($job['failed_at']) && isset($job['failed_at']['date'])) {
                $job['failed_at'] = Carbon::parse($job['failed_at']['date'])->toDateTimeString();
            }
            return (object)$job;
        }, $all);

        return $all;
    }
}

faze11 avatar Apr 27 '20 12:04 faze11

The problem occurs because of the way lumen loads service providers, it is necessary to assemble the queue before registering MongodbQueueServiceProvider. This works in a similar way to using email queues in the lumen where we should do the following:

$app->make('queue');
$app->configure('mail');
$app->alias('mailer', Illuminate\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);

lissonpsantos2 avatar May 01 '20 08:05 lissonpsantos2

I got the solution to this issue, would you still like it posted? If yes, please answer this issue and I will send here the necessary files for change and I will open a pull request to add the solution in the repo.

samuelrac avatar Oct 31 '21 18:10 samuelrac

I am experiencing this on Laravel 8,
image image

itsrexb avatar Aug 20 '22 12:08 itsrexb

https://jira.mongodb.org/browse/PHPORM-87

GromNaN avatar Sep 06 '23 16:09 GromNaN