I am writing Laravel json api using MySQL. What I am trying to do, is whenever user creates record, I want to perform some operation on this record every 24 hours, until some changes are made by admin on this record. So averagely this job will be repeated 10-15 times. this is my job:
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Http\Models\Orders\RoadOrder;
class RoadOrderEprirationHandler implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
protected $order_id;
public function __construct($order_id)
{
$this->order_id = $order_id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$order = RoadOrder::findOrFail($this->order_id);
//do some tasks and if I need to run this cycle again :
$roadOrderEprirationHandler = new RoadOrderEprirationHandler($order->id);
$roadOrderEprirationHandler->dispatch($order->id)->delay(now()->addHours(24));
}
}
So as you can see, I initiate job after previous job was finished if admin didn't modified record and I need to run cycle again. after several cycles, I won't run job again, so it will be finished.
My question:
Is some problem in this implementation? maybe I am doing something wrong or maybe there may occur some type of memory leak (because I create job inside job again and again). I can write this but I need to be sure that this implementation doesn't leads to some type of bugs or errors.