mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/docs/drivers/php/laravel-mongodb/
MIT License
7.02k stars 1.43k forks source link

artisan queue:retry all doesn't work #1560

Closed llioor closed 7 months ago

llioor commented 6 years ago

"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 [].

jra89 commented 6 years ago

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.

hazeem1991 commented 5 years ago

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

nicohell commented 5 years ago

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

Rodeoclash commented 5 years ago

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 commented 5 years ago

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.

ionutraducanu commented 5 years ago

@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

faze11 commented 4 years ago

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;
    }
}
lissonpsantos2 commented 4 years ago

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);
samuelrac commented 3 years ago

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.

itsrexb commented 2 years ago

I am experiencing this on Laravel 8,
image image

GromNaN commented 1 year ago

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

chrispage1 commented 7 months ago

I've just come across this with Laravel 11. A quick workaround is to jump in to artisan tinker and run:

DB::table('failed_jobs')->pluck('_id')->each(fn ($item) => Artisan::call('queue:retry', ['id' => (string)$item]))->count();

This will push all the failed jobs back into the queue. Not ideal, but it works!

GromNaN commented 7 months ago

I've an open PR to fix this issue: https://github.com/mongodb/laravel-mongodb/pull/2838

GromNaN commented 7 months ago

Fixed by #2838 (to be released in 4.3)

chrispage1 commented 6 months ago

Nice work @GromNaN ! Thanks