laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.21k stars 10.9k forks source link

Error when schedule not queued jobs #21818

Closed projct1 closed 6 years ago

projct1 commented 6 years ago

Description:

Trying to use not queued jobs in schedule, but getting error: Call to undefined method UpdateStatusSmsJob::onQueue(). Why? For queues has worker...

class Kernel extends ConsoleKernel
{
    ...

    protected function schedule(Schedule $schedule)
    {
        $schedule->job(new UpdateStatusSmsJob)->cron('*/3 * * * *');
    }

    ...
}

I have to use this:

    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function() {
            dispatch_now(new UpdateStatusSmsJob);
        })->cron('*/3 * * * *');
    }
themsaid commented 6 years ago

Please share full stack trace of the exception you get.

projct1 commented 6 years ago
[2017-10-25 20:33:03] production.ERROR: Call to undefined method App\Jobs\Sms\UpdateStatusSmsJob::onQueue() {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to undefined method App\\Jobs\\Sms\\UpdateStatusSmsJob::onQueue() at /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Foundation/Bus/PendingDispatch.php:48)
[stacktrace]
#0 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Console/Scheduling/Schedule.php(83): Illuminate\\Foundation\\Bus\\PendingDispatch->onQueue(NULL)
#1 [internal function]: Illuminate\\Console\\Scheduling\\Schedule->Illuminate\\Console\\Scheduling\\{closure}()
#2 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Object(Closure), Array)
#3 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(75): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#4 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Object(Closure), Object(Closure))
#5 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Object(Closure), Array, NULL)
#6 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Console/Scheduling/CallbackEvent.php(70): Illuminate\\Container\\Container->call(Object(Closure), Array)
#7 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Console/Scheduling/ScheduleRunCommand.php(59): Illuminate\\Console\\Scheduling\\CallbackEvent->run(Object(Illuminate\\Foundation\\Application))
#8 [internal function]: Illuminate\\Console\\Scheduling\\ScheduleRunCommand->handle()
#9 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#10 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#11 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#12 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#13 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Illuminate\\Container\\Container->call(Array)
#14 /home/v/vice159/bron-test.gdebar.ru/vendor/symfony/console/Command/Command.php(262): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#15 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Console/Command.php(167): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#16 /home/v/vice159/bron-test.gdebar.ru/vendor/symfony/console/Application.php(888): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 /home/v/vice159/bron-test.gdebar.ru/vendor/symfony/console/Application.php(224): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Console\\Scheduling\\ScheduleRunCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /home/v/vice159/bron-test.gdebar.ru/vendor/symfony/console/Application.php(125): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Console/Application.php(88): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#20 /home/v/vice159/bron-test.gdebar.ru/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 /home/v/vice159/bron-test.gdebar.ru/artisan(34): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 {main}
"} 
projct1 commented 6 years ago

This is my job:

class UpdateStatusSmsJob
{
    public function handle(Redsms $redsms)
    {
        //...
    }
}
themsaid commented 6 years ago

Looks like Schedule::job() is intended for use with queued jobs by design, using a closure as you do is the way to go in this case.

projct1 commented 6 years ago

Yea, but its strange. Jobs may not be queue. Callback example are cumbersome)

themsaid commented 6 years ago

Ok I've submitted a fix here https://github.com/laravel/framework/pull/21820

Thanks for reporting man :)