Laravel 5.1 jobs and listeners - php

So Laravel 5.1 changes the folders Commands to Jobs and Handlers to Listeners. What I'm a bit confused about is that the Listeners folder now only handles Events and not Jobs. Are all Jobs self-handling in 5.1? Or should i create a Handlers folder and handle the jobs in there?

For now, Jobs are self-handling. They are like Commands and implement the SelfHandling interface. The change is basically just a folder rename so people do not confuse it with other commands (e.g console commands). Try to think of a Job like a Command, since a command is actually performing a job.
Or still, you can create the app/Commands and app/Handlers directory and continue using commands as you are used to. Jobs and Commands are just different ways to do the same thing.

Related

How Laravel Generate Model Migration Controller all command related files?

after these commands
php artisan make:model 'FileName' -mcs
Laravel make command files sources (Model, Controller, Migration, Seeder, Factory etc...)
How all basic files generate and where from these files comes?
All the generated stuff in Laravel use templates
If you run artisan command in your console, you can observe that exists a section called stub, and the only command in this section is php artisan stub:publish.
If you run that command it will generate a new folder inn your app root folder called stubs with a bunch of files inside all with extension .stub.
You can open those files and modify then or customize them as needed. From now on this folder will be the place from where your Laravel app will read the template for making all kind of stuff that artisan usually does.
This templates are included with every Laravel installation and is totally optional publish them or not. In fact there are many packages dedicated to make custom Controllers or Models like this one from Spatie
The internals above this generators
Laravel has two kernels,
The first one in app/Console/kernel
The second one in app/Http/kernel
When you run artisan, Laravel Bootstrap the app, and run the Kernel console. This both Kernels has different purposes, really they function as separates apps.
About the specific generation of the above files, I mean different controllers, Models, migrations etc.. all that stuff related to models are generated by one Class.
class ModelMakeCommand extends GeneratorCommand{ .... }
Which is located under Illuminate\Foundation\Console namespace.
You can check the code of that class and see how the stubs files are used to generate the variety of commands only related to Models, but there are many more, like Policies, Events, Jobs etc...
I hope this helps and answer your question
Here you are more information about this subject from Laravel News
These files are being generated from stub files. Here are some stubs directory location on any laravel project. you can check this out.
For Model :
vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs/model.stub
Others :
vendor/laravel/framework/src/Illuminate/Foundation/Console/stubs
vendor/laravel/framework/src/Illuminate/Routing/Console/stubs
vendor/laravel/framework/src/Illuminate/Database/Console/Factories/stubs
vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/stubs
if you want control over these stubs you have to apply below command
php artisan stub:publish
this command will publish stub files on "stubs" folder on your project directory. Then you can customize according to your need.

Typo3 scheduler: Can i somehow execute Action of controllers of my extension with it? Or how to run my own code with it?

A while ago i was tasked to program a Typo3 extension to write so called .conf files for the icinga2 montoring tool (has nothing to do with Typo3). Still let me explain some parts of it: Basically the backend user needs to create records of records of specific classes and set values for each records properties. Then i need to process the records to create these .conf files with the specific values with a php script.
I was tasked to use the scheduler in Typo3 for this. And here come the problems: How do i use this? I checked the documentation (https://docs.typo3.org/typo3cms/extensions/scheduler/Introduction/Index.html), but i still can't wrap my head around how to use it for my task. I can easily write an Action in a controller of a class to be executed in the frontend and in turn generate the con files... basically manually without the scheduler. But where do i put my php code to be run by the scheduler? I somehow seem not to understand the basical principle of the scheduler. Can i just run an Action of a specific controller of a class of my extension like i would in the Frontend via the scheduler?
I would suggest you use a command controller for this task.
The documentation shows how to create a command controller, which also may accept arguments.
Command controller tasks can directly be executed by TYPO3 scheduler (see screenshot below)
You may even configure task arguments for command controller tasks in TYPO3 scheduler.

Executing bash scripts from Laravel

I am writing an app in Laravel that will interact with the server by executing bash scripts.
These scripts will create ftp users and manage directories.
What are the best practices when approaching this? I was thinking of writing a standard php function in laravel that would execute the bash script. Is there anything better or a bridge that would allow me to interact with server management through a php backend?
I have found that laravel has SSH tasks built in, would this be suitable?
https://laravel.com/docs/4.2/ssh
I would recommend looking into Envoy which is made for this kind of tasks. Using Blade style syntax, you can easily setup tasks for deployment, Artisan commands, and more.
https://laravel.com/docs/5.6/envoy

what is the best way to run a batch job using Symfony 2?

I have worked on Symfony 1.1 and http://www.lampjunkie.com/2008/04/how-to-use-symfony-and-cron/ is a doc I have come across online. For any batch job, it is required to load root directory path and make DB connections.
Is there any ready format or any plugin to create or run a batch file in Symfony 2?
The best way to do this is by creating a console command.
Check this : http://symfony.com/doc/2.8/console.html
Then you can use a crontab to call it

Laravel : Command bus not going asynchronous

I'm using Laravel 5.1's Command bus to run a specific task (upload a file, validate then record it in my db) on a background process.
I tried uploading small csv file like 1.4kb (40 rows) and it worked.
When when i tried uploading a 1MB csv file (20000 rows), I noticed it is not running in background process. It waits for the job to be finished and then loads the correct page which is not the way I wanted it :(.
I think I followed the Laravel documentation on how to run a command bus in asynchronous process just by php artisan make:command PurchasePodcast --queued.
Reference
My code :
class ImportPricelistCommand extends Command implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, SerializesModels;
Am i missing something? Please help.
In Laravel 5.1 the command bus is replace by jobs. You are using Laravel 5.1 and following 5.0 documentation.
The command bus was renamed jobs in Laravel 5.1, and the “command” stuff left to not break 5.0 applications. Jobs can be dispatched asynchronously as well as queued to be processed asynchronously.
Basically, you want to remove the ShouldQueue interface and InteractsWithQueue trait from your command/job class. As you may have gathered, this tells the dispatcher to queue them rather than process them synchronously.

Categories