diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 86981b0071..a94cde197d 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1155,7 +1155,8 @@ App::post('/v1/functions/:functionId/executions') ->setData($data) ->setJWT($jwt) ->setProject($project) - ->setUser($user); + ->setUser($user) + ->trigger(); return $response ->setStatusCode(Response::STATUS_CODE_ACCEPTED) diff --git a/app/workers/functions.php b/app/workers/functions.php index 906ae25d38..d503fdc5e0 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -282,6 +282,48 @@ $server->job() return; } + if (!empty($events)) { + $limit = 30; + $sum = 30; + $offset = 0; + $functions = []; + /** @var Document[] $functions */ + while ($sum >= $limit) { + $functions = $dbForProject->find('functions', [ + Query::limit($limit), + Query::offset($offset), + Query::orderAsc('name'), + ]); + + $sum = \count($functions); + $offset = $offset + $limit; + + Console::log('Fetched ' . $sum . ' functions...'); + + foreach ($functions as $function) { + if (!array_intersect($events, $function->getAttribute('events', []))) { + continue; + } + Console::success('Iterating function: ' . $function->getAttribute('name')); + $execute( + statsd: $statsd, + dbForProject: $dbForProject, + project: $project, + function: $function, + queueForFunctions: $queueForFunctions, + trigger: $type, + event: $events[0], + eventData: $eventData, + user: $user, + data: null, + executionId: null, + jwt: null + ); + Console::success('Triggered function: ' . $events[0]); + } + } + } + /** * Handle Schedule and HTTP execution. */ @@ -321,49 +363,6 @@ $server->job() statsd: $statsd, ); break; - case 'event': - if (!empty($events)) { - $limit = 30; - $sum = 30; - $offset = 0; - $functions = []; - /** @var Document[] $functions */ - while ($sum >= $limit) { - $functions = $dbForProject->find('functions', [ - Query::limit($limit), - Query::offset($offset), - Query::orderAsc('name'), - ]); - - $sum = \count($functions); - $offset = $offset + $limit; - - Console::log('Fetched ' . $sum . ' functions...'); - - foreach ($functions as $function) { - if (!array_intersect($events, $function->getAttribute('events', []))) { - continue; - } - Console::success('Iterating function: ' . $function->getAttribute('name')); - $execute( - statsd: $statsd, - dbForProject: $dbForProject, - project: $project, - function: $function, - queueForFunctions: $queueForFunctions, - trigger: $type, - event: $events[0], - eventData: $eventData, - user: $user, - data: null, - executionId: null, - jwt: null - ); - Console::success('Triggered function: ' . $events[0]); - } - } - } - break; } });