Answer the question
In order to leave comments, you need to log in
How to create a job for Laravel console command?
Kind everyone. I have a console command that runs on a schedule. I need to create a Job which, after executing the console command, wrote to the log that the task was completed or not completed.
Team:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class RefreshDb extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'create:refdb';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Refresh Database';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$remote = DB::connection('sqlsrv')->select('SELECT TOP (5) * FROM [dbo].[Level]');
foreach ($remote as $record) {
DB::connection('mysql')->insert('insert into level (driver) values (?)', [$record->DriveID]);
}
// $local = DB::connection('sqlite')->select('SELECT * FROM level');
return 0;
}
}
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendMessegeWhenDbUpdate implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
logs()->info("Database Uodate Success");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question