1
0
Fork 0
mirror of synced 2024-07-01 12:40:34 +12:00

Updated functions trigger

This commit is contained in:
Eldad Fux 2021-05-17 14:32:37 +03:00
parent af470a3f1a
commit a8cc398c85
3 changed files with 9 additions and 5 deletions

View file

@ -321,6 +321,7 @@ App::put('/v1/functions/:functionId')
if ($next && $schedule !== $original) { if ($next && $schedule !== $original) {
ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [
'projectId' => $project->getId(), 'projectId' => $project->getId(),
'webhooks' => $project->getAttribute('webhooks', []),
'functionId' => $function->getId(), 'functionId' => $function->getId(),
'executionId' => null, 'executionId' => null,
'trigger' => 'schedule', 'trigger' => 'schedule',
@ -375,6 +376,7 @@ App::patch('/v1/functions/:functionId/tag')
if ($next) { // Init first schedule if ($next) { // Init first schedule
ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [ ResqueScheduler::enqueueAt($next, 'v1-functions', 'FunctionsV1', [
'projectId' => $project->getId(), 'projectId' => $project->getId(),
'webhooks' => $project->getAttribute('webhooks', []),
'functionId' => $function->getId(), 'functionId' => $function->getId(),
'executionId' => null, 'executionId' => null,
'trigger' => 'schedule', 'trigger' => 'schedule',

View file

@ -76,6 +76,7 @@ App::init(function ($utopia, $request, $response, $project, $user, $register, $e
*/ */
$events $events
->setParam('projectId', $project->getId()) ->setParam('projectId', $project->getId())
->setParam('webhooks', $project->getAttribute('webhooks', []))
->setParam('userId', $user->getId()) ->setParam('userId', $user->getId())
->setParam('event', $route->getLabel('event', '')) ->setParam('event', $route->getLabel('event', ''))
->setParam('eventData', []) ->setParam('eventData', [])
@ -188,7 +189,6 @@ App::shutdown(function ($utopia, $request, $response, $project, $events, $audits
$webhooks $webhooks
->setQueue('v1-webhooks') ->setQueue('v1-webhooks')
->setClass('WebhooksV1') ->setClass('WebhooksV1')
->setParam('webhooks', $project->getAttribute('webhooks', []))
->trigger(); ->trigger();
$functions $functions

View file

@ -141,6 +141,7 @@ class FunctionsV1
$projectId = $this->args['projectId'] ?? ''; $projectId = $this->args['projectId'] ?? '';
$functionId = $this->args['functionId'] ?? ''; $functionId = $this->args['functionId'] ?? '';
$webhooks = $this->args['webhooks'] ?? [];
$executionId = $this->args['executionId'] ?? ''; $executionId = $this->args['executionId'] ?? '';
$trigger = $this->args['trigger'] ?? ''; $trigger = $this->args['trigger'] ?? '';
$event = $this->args['event'] ?? ''; $event = $this->args['event'] ?? '';
@ -196,7 +197,7 @@ class FunctionsV1
Console::success('Triggered function: '.$event); 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; break;
@ -252,7 +253,7 @@ class FunctionsV1
'scheduleOriginal' => $function->getAttribute('schedule', ''), 'scheduleOriginal' => $function->getAttribute('schedule', ''),
]); // Async task rescheduale ]); // 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; break;
case 'http': case 'http':
@ -264,7 +265,7 @@ class FunctionsV1
throw new Exception('Function not found ('.$functionId.')'); 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; break;
default: default:
@ -287,7 +288,7 @@ class FunctionsV1
* *
* @return void * @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; global $list;
@ -479,6 +480,7 @@ class FunctionsV1
$executionUpdate $executionUpdate
->setParam('projectId', $projectId) ->setParam('projectId', $projectId)
->setParam('userId', $userId) ->setParam('userId', $userId)
->setParam('webhooks', $webhooks)
->setParam('event', 'functions.executions.update') ->setParam('event', 'functions.executions.update')
->setParam('eventData', [ ->setParam('eventData', [
'$id' => $execution['$id'], '$id' => $execution['$id'],