Skip to content

Commit

Permalink
Webhook job no longer duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Apr 10, 2024
1 parent 336cf30 commit 47bb985
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/Observers/EntityObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Services\ImageService;
use App\Services\PermissionService;
use App\Facades\Domain;
use Carbon\Carbon;

class EntityObserver
{
Expand Down Expand Up @@ -189,7 +190,7 @@ public function created(Entity $entity)
if (!request()->has('attr_name')) {
$this->attributeService->applyEntityTemplates($entity);
}
EntityWebhookJob::dispatch($entity, auth()->user(), WebhookAction::NEW);
EntityWebhookJob::dispatch($entity, auth()->user(), WebhookAction::NEW->value);
}

/**
Expand All @@ -200,7 +201,15 @@ public function updated(Entity $entity)

// Queue job when an entity was updated
EntityUpdatedJob::dispatch($entity);
EntityWebhookJob::dispatch($entity, auth()->user(), WebhookAction::EDITED);
}

/**
*/
public function updating(Entity $entity)
{
if ($entity->getOriginal('updated_at')->diffInSeconds(Carbon::now()) > 15) {
EntityWebhookJob::dispatch($entity, auth()->user(), WebhookAction::EDITED->value);
}
}

/**
Expand Down Expand Up @@ -243,7 +252,7 @@ public function saveBoosted(Entity $entity): void

public function deleting(Entity $entity)
{
EntityWebhookJob::dispatch($entity, auth()->user(), WebhookAction::DELETED);
EntityWebhookJob::dispatch($entity, auth()->user(), WebhookAction::DELETED->value);
}

/**
Expand Down

0 comments on commit 47bb985

Please sign in to comment.