Fixed event triggers
This commit is contained in:
parent
05c01dc1a7
commit
a361b3d181
|
@ -220,7 +220,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo
|
|||
*/
|
||||
$functions
|
||||
->setParam('projectId', $project->getId())
|
||||
->setParam('event', $route->getLabel('events', ''))
|
||||
->setParam('event', $route->getLabel('event', ''))
|
||||
->setParam('payload', [])
|
||||
->setParam('functionId', null)
|
||||
->setParam('executionId', null)
|
||||
|
@ -229,7 +229,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo
|
|||
|
||||
$webhooks
|
||||
->setParam('projectId', $project->getId())
|
||||
->setParam('event', $route->getLabel('events', ''))
|
||||
->setParam('event', $route->getLabel('event', ''))
|
||||
->setParam('payload', [])
|
||||
;
|
||||
|
||||
|
@ -266,6 +266,7 @@ App::shutdown(function ($utopia, $request, $response, $project, $webhooks, $audi
|
|||
/** @var Appwrite\Event\Event $functions */
|
||||
/** @var bool $mode */
|
||||
|
||||
var_dump($functions->getParam('event'));
|
||||
if (!empty($functions->getParam('event'))) {
|
||||
$functions->trigger();
|
||||
}
|
||||
|
|
|
@ -129,15 +129,6 @@ class FunctionsV1
|
|||
$functions = []; /** @var Document[] $functions */
|
||||
|
||||
while ($sum >= $limit) {
|
||||
foreach($functions as $function) {
|
||||
$events = $function->getAttribute('events', []);
|
||||
|
||||
if(!\in_array($event, $events)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->execute('event', $projectId, $executionId, $database, $function);
|
||||
}
|
||||
|
||||
Authorization::disable();
|
||||
|
||||
|
@ -158,6 +149,21 @@ class FunctionsV1
|
|||
$offset = $offset + $limit;
|
||||
|
||||
Console::log('Fetched '.$sum.' functions...');
|
||||
|
||||
foreach($functions as $function) {
|
||||
$events = $function->getAttribute('events', []);
|
||||
$tag = $function->getAttribute('tag', []);
|
||||
|
||||
Console::success('Itterating function: '.$function->getAttribute('name'));
|
||||
|
||||
if(!\in_array($event, $events) || empty($tag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Console::success('Triggered function: '.$event);
|
||||
|
||||
$this->execute('event', $projectId, '', $database, $function);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -199,17 +205,15 @@ class FunctionsV1
|
|||
|
||||
Authorization::disable();
|
||||
|
||||
$execution = $database->getDocument($executionId);
|
||||
|
||||
if (empty($execution->getId()) || Database::SYSTEM_COLLECTION_EXECUTIONS != $execution->getCollection()) {
|
||||
$execution = $database->createDocument([
|
||||
$execution = (!empty($executionId)) ? $database->getDocument($executionId) : $database->createDocument([
|
||||
'$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
|
||||
'$permissions' => [
|
||||
'read' => [],
|
||||
'write' => [],
|
||||
],
|
||||
'dateCreated' => \time(),
|
||||
'dateCreated' => time(),
|
||||
'functionId' => $function->getId(),
|
||||
'trigger' => $trigger, // http / schedule / event
|
||||
'status' => 'processing', // waiting / processing / completed / failed
|
||||
'exitCode' => 0,
|
||||
'stdout' => '',
|
||||
|
@ -217,9 +221,8 @@ class FunctionsV1
|
|||
'time' => 0,
|
||||
]);
|
||||
|
||||
if (false === $execution) {
|
||||
throw new Exception('Failed saving execution to DB', 500);
|
||||
}
|
||||
if(false === $execution) {
|
||||
throw new Exception('Failed to create execution');
|
||||
}
|
||||
|
||||
Authorization::reset();
|
||||
|
@ -232,6 +235,8 @@ class FunctionsV1
|
|||
throw new Exception('Environment "'.$function->getAttribute('env', '').' is not supported');
|
||||
}
|
||||
|
||||
var_dump($function->getAttribute('name', ''));
|
||||
var_dump($function->getAttribute('vars', []));
|
||||
$vars = \array_merge($function->getAttribute('vars', []), [
|
||||
'APPWRITE_FUNCTION_ID' => $function->getId(),
|
||||
'APPWRITE_FUNCTION_NAME' => $function->getAttribute('name', ''),
|
||||
|
|
|
@ -157,7 +157,7 @@ class Database
|
|||
$results = $this->adapter->getCollection($options);
|
||||
|
||||
foreach ($results as &$node) {
|
||||
$node = new Document($node);
|
||||
$node = $this->decode(new Document($node));
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
|
Loading…
Reference in a new issue