i want to implement custom queue management system and want to listen to events if any new record is added in table jobs.
I had made on command
php artisan MyQueue:work
the command is working fine but it's not waiting for the event.
I found this code in the official queue:work commands file. but it was not working for my own custom class.
$this->laravel['events']->listen(JobProcessing::class, function ($event) {
$this->writeOutput($event->job, 'starting');
});
So is there any way to listen to the event from the Model to the command file?
is there any way to get this event in handle method of this command
class MyQueue extends Command
{
protected $signature = 'MyQueue:work';
protected $description = 'use to listen custom queeue';
public function handle()
{
$this->line("<info>Starting MyQueue:</info>");
// Is there any way to get model insert event heree //////////////////////////////
$this->laravel['events']->listen(JobEvent::class, function ($event) {
$this->startPendingJobs();
});
}
private function startPendingJobs()
{
$jobs = Job::whereState(0)->get();
foreach ($jobs as $job) {
$this->performJob($job);
}
}
private function performJob($job)
{
$this->line("<fg=gray> Stating job " . $job->id . " </>");
Log::info("Job completed " . $job->id);
$this->line(" <fg=green> Completed job " . $job->id . " </>");
$job->delete();
}
}