In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use the Queue method of laravel source code analysis queue". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Creation of queue tasks
First create a Job class with the command, and after success, the following file laravel-src/laravel/app/Jobs/DemoJob.php will be created.
> php artisan make:job DemoJob > Job created successfully.
Let's analyze the specific generation process of the Job class.
After the php artisan make:job DemoJob is executed, the following method is triggered.
Laravel-src/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
/ * Register the command. * method triggered by [A] make:job * @ return void * / protected function registerJobMakeCommand () {$this- > app- > singleton ('command.job.make', function ($app) {return new JobMakeCommand ($app [' files']);});}
Then let's take a look at the JobMakeCommand class, which does not have too much processing logic, and the processing method is in its parent class.
Class JobMakeCommand extends GeneratorCommand
Let's look directly at the processing method in the parent class, GeneratorCommand- > handle (). Here are the main methods in this method.
Public function handle () {/ / get the class name $name = $this- > qualifyClass ($this- > getNameInput ()); / / get the file path $path = $this- > getPath ($name); / / create directories and files $this- > makeDirectory ($path); / / buildClass () get the contents of the new class file $this- > files- > put ($path, $this- > buildClass ($name) through the template) / / $this- > type is defined in the subclass, for example, type = 'Job' $this- > info ($this- > type.') in JobMakeCommand Created successfully.');}
The method is to create the corresponding class file through the directory and file. As for the content of the new file, it is based on the template that has been set up. The specific content is in the buildClass ($name) method.
Protected function buildClass ($name) {/ / gets the class file template, and getStub () is implemented in the subclass, such as JobMakeCommand $stub = $this- > files- > get ($this- > getStub ()); / / replace the content in the template with the actual name, with the keywords return $this- > replaceNamespace ($stub, $name)-> replaceClass ($stub, $name);}
Get template file
Protected function getStub () {return $this- > option ('sync')? _ _ DIR__.'/stubs/job.stub': _ _ DIR__.'/stubs/job-queued.stub';}
Job.stub
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.