Fix multiple notifications send to PIC at one time

- fix by removing previous scheduled notifications job before updating the notification configurations
This commit is contained in:
Afiq Hamzah
2024-06-04 18:48:06 +08:00
parent 052f65307d
commit cbf6bd5f1f
7 changed files with 65 additions and 98 deletions
+5 -25
View File
@@ -2,7 +2,6 @@
namespace App\Jobs;
use App\JobStatus;
use App\Setting;
use Carbon\Carbon;
@@ -10,7 +9,6 @@ class WhatsappUnsoldCommodityScanner extends Job
{
public $status;
public $start_time;
public $end_time;
public $message;
/**
@@ -30,33 +28,15 @@ class WhatsappUnsoldCommodityScanner extends Job
public function handle()
{
$settings = Setting::on('mysql7')->where('group', 'unsold_commodity_notifications')->get();
$status = $settings->where('key', 'status')->first()->value;
$start_time = $settings->where('key', 'start_time')->first()->value;
$this->status = $settings->where('key', 'status')->first()->value;
$this->start_time = $settings->where('key', 'start_time')->first()->value;
$this->end_time = $settings->where('key', 'end_time')->first()->value;
$this->message = $settings->where('key', 'message')->first()->value;
if ($this->status === '0') {
return;
if ($status === '0') {
return false;
}
if (Carbon::parse($this->start_time) > Carbon::now()) {
return;
}
dispatch((new WhatsappUnsoldCommodityNotification($this->message))->delay(Carbon::parse($start_time)));
if (Carbon::parse($this->end_time) < Carbon::now()) {
return;
}
$job_id = dispatch((new WhatsappUnsoldCommodityNotification($this->message))->delay(Carbon::parse($this->start_time)));
JobStatus::on('mysql7')->create([
'job_id' => $job_id,
'type' => WhatsappUnsoldCommodityNotification::class,
'status' => true,
]);
}
}