There is a small service for statistics in development. The essence of the task on the crown is to remove positions from Yandex.

According to the results: go to the Kernel class, schedule method and write the following:

 $schedule ->job(new RemoverPositions) ->withoutOverlapping() ->runInBackground() ->everyMinute() ->emailOutputTo("g7-99055@yandex.ru"); 

Employee code RemoverPositions :

 class RemoverPositions implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; /** * Create a new job instance. * * @return void */ public function __construct() { $this->test("construct run"); } public function test($value) { //sleep(10); (new Test([ "value" => $value ]))->save(); } public function __invoke() { $this->test("invoke"); } /** * Execute the job. * * @return void */ public function handle() { $this->test("handle"); } } 

As a result, once a minute and with each request this method is jerked (for some reason, only the constructor works). How to make it so that with ordinary requests (for example, opening a page), he would not do this and still run in the background?

PS: In Laravel completely green, as in the fenemvorki in general, I strongly ask you not to kick)

// UPD: And also when trying to execute the console:

No scheduled commands are ready to run.

  • And where does the Test class connect in the test method - lazyproger
  • Test - this is the usual model for all occasions use App \ Test - Morfeey Hard

1 answer 1

Such things are done through the laravel console artisan commands :

php artisan make:command CommandName after which the app/Console/Commands/CommandName.php class will be automatically created in it sets the call signature and command description for example:

 protected $signature = 'command:start'; protected $description = 'Моя тестовая команда'; 

In the handle() method, the logic of the program.

 public function handle() { echo 'РАБОТАЕТ'; } 

Next, in app/Console/Kernel.php you need to register the console command as follows

 protected $commands = [ ... Commands\CommandName::class, ]; 

And in the shedule () method of the same class

 protected function schedule(Schedule $schedule) { ... $schedule->command(Commands\CommandName::class)->everyMinute(); } 

After that, the command runs every minute, and if you type in the php artisan console, you will see a list of all the commands, including the command:start that we created, which you can run php artisan command:start .