G
G
Gramcoder2020-02-12 21:19:00
Laravel
Gramcoder, 2020-02-12 21:19:00

How to correctly implement task execution in laravel task scheduler?

Interested in the logic itself, how to organize it?
Currently, I have a task running through the created command App\Console\Commands\MyCommand, which is called once a minute in App\Console\Kernel:

protected function schedule(Schedule $schedule)
    {
        $schedule->command('mycommand:run')->everyMinute();
    }


And everything works fine, but it seems to me that the logic can be organized more correctly.

The task itself is that once a minute you need to sample the latest data from the database, process it and send it to me in telegrams.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Kulaxyz, 2020-02-13
@Gramcoder

Laravel already has a great tool that you use and does a great job. No jobs are needed here. If you are confused that there is too much code in one handle method, you can simply create a layer like UserRepository and thereby make the method more readable and fault-tolerant by breaking it into small components.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question