Reputation: 499
I'm developing an application in Laravel, my concept is ordered will be posted by buyers to buy particular items. I'm having a setting like order lifetime 5 min. This order will be notified to sellers whoever nearest to the buyer location. After 5 min completed need to take a list of viewed sellers and then need to change the order status as a timeout. I have to do this in my Laravel application hosted in VPS. Is there I can create events listen to the orders and update the status by using order date time and a current date time. Now I have a code like below and manually triggering this API, Is there any other way to do this automated. Please help any one
$postrequests = Buyrequest::where('request_closed' , 0)->whereDate('request_on', '=', date('Y-m-d'))->get();
if(count($postrequests) >0){
$trade_execution = Adminsetting::where('id_admin_settings', 1)->selectRaw("TIME_TO_SEC(trade_execution_time) / 60 as trade_execution_time")->first();
}
foreach($postrequests as $request){
if(Carbon::createFromFormat('Y-m-d H:i:s', $request->request_on) < Carbon::now()->subMinutes($trade_execution->trade_execution_time)->toDateTimeString()){
if($request->request_status == 0){
Buyrequest::where('id_buyrequest', $request->id_buyrequest)->update(['request_status' => 2, 'request_closed' => 1]);
}else{
Buyrequest::where('id_buyrequest', $request->id_buyrequest)->update(['request_closed' => 1]);
}
}
}
Upvotes: 0
Views: 1240
Reputation: 5129
You can setup queue worker to handle this situation. If buy request is created, then you can dispatch job and delay it to 5 mins, then worker will consume it after 5 mins.
dispatch((new BuyRequestJob($buyRequestId))->delay(now()->addMinutes(5));
Upvotes: 1