Skip to content

Commit

Permalink
added delivery job
Browse files Browse the repository at this point in the history
  • Loading branch information
199ocero committed Jun 1, 2024
1 parent 3793a6b commit 22db160
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions app/Jobs/Ses/DeliveryJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace App\Jobs\Ses;

use App\Enum\CampaignLogStatusType;
use App\Models\CampaignEmail;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Spatie\WebhookClient\Models\WebhookCall;

class DeliveryJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*/
public function __construct(public WebhookCall $webhookCall)
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{
$message = $this->webhookCall->payload['Message'];

$campaignId = null;
$subscriberId = null;

foreach ($message['mail']['headers'] as $header) {
if ($header['name'] === 'Campaign-Id') {
$campaignId = $header['value'];
break;
}
}

foreach ($message['mail']['headers'] as $header) {
if ($header['name'] === 'Subscriber-Id') {
$subscriberId = $header['value'];
break;
}
}

$campaignLog = CampaignEmail::query()
->with('subscriber')
->where('campaign_id', $campaignId)
->where('subscriber_id', $subscriberId)
->first();

if ($campaignLog) {
$campaignLog->status = CampaignLogStatusType::DELIVERED->value;
$campaignLog->delivered_at = Carbon::parse($message['mail']['timestamp']);
$campaignLog->save();
}
}
}

0 comments on commit 22db160

Please sign in to comment.