I have finished the part of an application dedicated to backups. Now when I try to implement it using the queues and tasks of laravel 5.3, I feel incapable.
I have some sort of commands
cpr:backups {full|acct} {full|account} {daily|weekly|monthly}
cpr:backup {account|system} {full|account} {daily|weekly|monthly}
The first cpr: backups can generate (or must generate because I have already lost) or a task or as many tasks as users are in the independent system, which should be "glued" to be executed later.
in cron
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
In the file that controls the backups
...
foreach ($users as $user)
{
// $type puede ser daily|weekly|monthly
$job = new MakeBackups($user->id,$model);
dispatch($job);
}
In the app \ Jobs \ MakeBackups.php file
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Log;
class MakeBackups implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $userId;
protected $model;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($userId,$model)
{
$this->userId = $userId;
$this->model = $model;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// Do something
Log::info('Make a backups for user with id '.$this->userId.' within the User class');
}
When I verify, a job has been effectively added to the jobs table by each of the users
queue -> default
payload -> {"job":"Illuminate\Queue\CallQueuedHandler@call","data":{"commandName":"App\Jobs\MakeBackups","command":"O:20:\"App\Jobs\MakeBackups\":5:{s:9:\"\u0000*\u0000userId\";s:1:\"1\";s:6:\"\u0000*\u0000job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:5:\"delay\";N;}"}}
But if I try to manually execute the queue.
artisan schedule:run
No scheduled commands are ready to run.
At this point, I understand that I have not comrpendido the basic operation of the tasks or queues, in deferred.