webhook_listeners creates a background job with a payload from the webhook event.
If the payload is bigger then:
- Webhook is not created
- A request creating the event fails
background job arguments cannot exceed 4000 characters
|
class WebhooksEventListener implements IEventListener { |
|
public function __construct( |
|
private WebhookListenerMapper $mapper, |
|
private IJobList $jobList, |
|
private LoggerInterface $logger, |
|
private IUserSession $userSession, |
|
) { |
|
} |
|
|
|
public function handle(Event $event): void { |
|
$user = $this->userSession->getUser(); |
|
$webhookListeners = $this->mapper->getByEvent($event::class, $user?->getUID()); |
|
|
|
foreach ($webhookListeners as $webhookListener) { |
|
// TODO add group membership to be able to filter on it |
|
$data = [ |
|
'event' => $this->serializeEvent($event), |
|
/* Do not remove 'user' from here, see BackgroundJobs/WebhookCall.php */ |
|
'user' => (is_null($user) ? null : JsonSerializer::serializeUser($user)), |
|
'time' => time(), |
|
]; |
|
if ($this->filterMatch($webhookListener->getEventFilter(), $data)) { |
|
$this->jobList->add( |
|
WebhookCall::class, |
|
[ |
|
$data, |
|
$webhookListener->getId(), |
|
/* Random string to avoid collision with another job with the same parameters */ |
|
bin2hex(random_bytes(5)), |
|
] |
|
); |
|
} |
|
} |
|
} |
Intermediate solution: at least wrap it into a try catch block and log the error, so failed background job creation doesn't fail the request.
A proper solution is to store the data somewhere else or add support for large data in background jobs.
cc @come-nc @artonge
webhook_listenerscreates a background job with a payload from the webhook event.If the payload is bigger then:
server/apps/webhook_listeners/lib/Listener/WebhooksEventListener.php
Lines 27 to 60 in 72c3793
Intermediate solution: at least wrap it into a try catch block and log the error, so failed background job creation doesn't fail the request.
A proper solution is to store the data somewhere else or add support for large data in background jobs.
cc @come-nc @artonge