Skip to content

Commit a7e4921

Browse files
authored
Merge pull request #16 from OnrampLab/15-make-webhookdispatcher-implements-shouldqueue
feat: make Webhook async
2 parents aad2101 + a8508da commit a7e4921

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/WebhookDispatcher.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
namespace OnrampLab\Webhooks;
44

55
use Carbon\Carbon;
6-
use Illuminate\Foundation\Bus\PendingDispatch;
76
use Illuminate\Support\Collection;
8-
use OnrampLab\Webhooks\Contracts\Webhookable;
97
use OnrampLab\Webhooks\Models\Webhook;
8+
use Illuminate\Contracts\Queue\ShouldQueue;
9+
use OnrampLab\Webhooks\Contracts\Webhookable;
10+
use Illuminate\Foundation\Bus\PendingDispatch;
1011

11-
class WebhookDispatcher
12+
class WebhookDispatcher implements ShouldQueue
1213
{
14+
public string $queue;
15+
1316
protected ?Carbon $eventOccurredAt;
1417

18+
public function __construct()
19+
{
20+
$this->queue = config('laravel-webhooks.queue', 'default');
21+
}
22+
1523
public function handle(Webhookable $event)
1624
{
1725
$webhooks = $this->getWebhooks($event);
@@ -76,8 +84,7 @@ protected function areExclusionCriteriaMatched(Webhookable $event, Webhook $webh
7684
protected function dispatchWebhook(array $payload, Webhook $webhook): PendingDispatch
7785
{
7886
$callWebhookJob = new CallWebhookJob($payload, $webhook, $this->eventOccurredAt);
79-
$config = config('laravel-webhooks');
80-
return dispatch($callWebhookJob)->onQueue($config['queue']);
87+
return dispatch($callWebhookJob)->onQueue($this->queue);
8188
}
8289
}
8390

0 commit comments

Comments
 (0)