This commit is contained in:
Afiq Hamzah
2024-05-31 14:49:41 +08:00
parent 931de4471c
commit 052f65307d
4 changed files with 69 additions and 7 deletions
@@ -2,6 +2,7 @@
namespace App\Jobs;
use App\JobStatus;
use Illuminate\Support\Facades\Http;
use App\Setting;
use Carbon\Carbon;
@@ -56,6 +57,10 @@ class WhatsappUnsoldCommodityNotification extends Job
return;
}
if(JobStatus::where('job_id', $this->job->getJobId()) === false){
return;
}
if ($this->status === '0') {
return;
}
@@ -68,9 +73,9 @@ class WhatsappUnsoldCommodityNotification extends Job
return;
}
if (!$isKomoditiStillAvailable) {
return;
}
// if (!$isKomoditiStillAvailable) {
// return;
// }
foreach ($phone_numbers as $phone_number) {
Http::get(env('WABOT_API'), [
@@ -82,6 +87,13 @@ class WhatsappUnsoldCommodityNotification extends Job
]);
}
dispatch((new WhatsappUnsoldCommodityNotification($this->message))->delay(Carbon::now()->addMinutes(5)));
$job_id = dispatch((new WhatsappUnsoldCommodityNotification($this->message))->delay(Carbon::now()->addMinutes(1)));
Log::info($job_id);
JobStatus::on('mysql7')->create([
'job_id' => $job_id,
'type' => WhatsappUnsoldCommodityNotification::class,
'status' => true,
]);
}
}
+9 -2
View File
@@ -2,6 +2,7 @@
namespace App\Jobs;
use App\JobStatus;
use App\Setting;
use Carbon\Carbon;
@@ -28,7 +29,7 @@ class WhatsappUnsoldCommodityScanner extends Job
*/
public function handle()
{
$settings = Setting::on()->where('group', 'unsold_commodity_notifications')->get();
$settings = Setting::on('mysql7')->where('group', 'unsold_commodity_notifications')->get();
$this->status = $settings->where('key', 'status')->first()->value;
@@ -50,6 +51,12 @@ class WhatsappUnsoldCommodityScanner extends Job
return;
}
dispatch((new WhatsappUnsoldCommodityNotification($this->message))->delay(Carbon::parse($this->start_time)));
$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,
]);
}
}