diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index ff8b7d5bc..e74fc0ee1 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -321,6 +321,7 @@ App::put('/v1/functions/:functionId') if ($next && $schedule !== $original) { ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ 'projectId' => $project->getId(), + 'webhooks' => $project->getAttribute('webhooks', []), 'functionId' => $function->getId(), 'executionId' => null, 'trigger' => 'schedule', @@ -375,6 +376,7 @@ App::patch('/v1/functions/:functionId/tag') if ($next) { // Init first schedule ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ 'projectId' => $project->getId(), + 'webhooks' => $project->getAttribute('webhooks', []), 'functionId' => $function->getId(), 'executionId' => null, 'trigger' => 'schedule', diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 0fca084db..a6c2b4173 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -76,6 +76,7 @@ App::init(function ($utopia, $request, $response, $project, $user, $register, $e */ $events ->setParam('projectId', $project->getId()) + ->setParam('webhooks', $project->getAttribute('webhooks', [])) ->setParam('userId', $user->getId()) ->setParam('event', $route->getLabel('event', '')) ->setParam('eventData', []) @@ -188,7 +189,6 @@ App::shutdown(function ($utopia, $request, $response, $project, $events, $audits $webhooks ->setQueue('v1-webhooks') ->setClass('WebhooksV1') - ->setParam('webhooks', $project->getAttribute('webhooks', [])) ->trigger(); $functions diff --git a/app/workers/functions.php b/app/workers/functions.php index 7ea356464..33b300d54 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -141,6 +141,7 @@ class FunctionsV1 $projectId = $this->args['projectId'] ?? ''; $functionId = $this->args['functionId'] ?? ''; + $webhooks = $this->args['webhooks'] ?? []; $executionId = $this->args['executionId'] ?? ''; $trigger = $this->args['trigger'] ?? ''; $event = $this->args['event'] ?? ''; @@ -196,7 +197,7 @@ class FunctionsV1 Console::success('Triggered function: '.$event); - $this->execute('event', $projectId, '', $database, $function, $event, $eventData, $data, $userId, $jwt); + $this->execute('event', $projectId, '', $database, $function, $event, $eventData, $data, $webhooks, $userId, $jwt); } } break; @@ -252,7 +253,7 @@ class FunctionsV1 'scheduleOriginal' => $function->getAttribute('schedule', ''), ]); // Async task rescheduale - $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $userId, $jwt); + $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $webhooks, $userId, $jwt); break; case 'http': @@ -264,7 +265,7 @@ class FunctionsV1 throw new Exception('Function not found ('.$functionId.')'); } - $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $userId, $jwt); + $this->execute($trigger, $projectId, $executionId, $database, $function, /*$event*/'', /*$eventData*/'', $data, $webhooks, $userId, $jwt); break; default: @@ -287,7 +288,7 @@ class FunctionsV1 * * @return void */ - public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $eventData = '', string $data = '', string $userId = '', string $jwt = ''): void + public function execute(string $trigger, string $projectId, string $executionId, Database $database, Document $function, string $event = '', string $eventData = '', string $data = '', array $webhooks = [], string $userId = '', string $jwt = ''): void { global $list; @@ -479,6 +480,7 @@ class FunctionsV1 $executionUpdate ->setParam('projectId', $projectId) ->setParam('userId', $userId) + ->setParam('webhooks', $webhooks) ->setParam('event', 'functions.executions.update') ->setParam('eventData', [ '$id' => $execution['$id'],