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