From 4a9f0a5ebba763a29d2cedf36718c269dc327d6d Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 23 Jul 2020 08:52:03 +0300 Subject: [PATCH] Added function trigger --- app/config/collections.php | 9 +++++++++ app/controllers/api/functions.php | 3 ++- app/views/console/functions/function.phtml | 8 ++++++-- app/workers/functions.php | 11 ++++------- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 2f630e0ba1..ca8917013f 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1395,6 +1395,15 @@ $collections = [ 'required' => false, 'array' => false, ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Trigger', + 'key' => 'trigger', + 'type' => Database::SYSTEM_VAR_TYPE_TEXT, + 'default' => '', + 'required' => false, + 'array' => false, + ], [ '$collection' => Database::SYSTEM_COLLECTION_RULES, 'label' => 'Exit Code', diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 11c30c4789..aac61d5a03 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -564,6 +564,7 @@ App::post('/v1/functions/:functionId/executions') 'dateCreated' => time(), 'functionId' => $function->getId(), 'status' => 'waiting', // waiting / processing / completed / failed + 'trigger' => 'http', // http / schedule / event 'exitCode' => 0, 'stdout' => '', 'stderr' => '', @@ -581,7 +582,7 @@ App::post('/v1/functions/:functionId/executions') 'functionId' => $function->getId(), 'executionId' => $execution->getId(), 'functionTag' => $tag->getId(), - 'functionTrigger' => 'API', + 'functionTrigger' => 'http', ]); } diff --git a/app/views/console/functions/function.phtml b/app/views/console/functions/function.phtml index 3367c6d755..71826d6039 100644 --- a/app/views/console/functions/function.phtml +++ b/app/views/console/functions/function.phtml @@ -282,9 +282,10 @@ $timeout = $this->getParam('timeout', 900); - Triggered + Created Status - Runtime + Trigger + Runtime @@ -303,6 +304,9 @@ $timeout = $this->getParam('timeout', 900); + + + - diff --git a/app/workers/functions.php b/app/workers/functions.php index 98597dae3d..9296a4855c 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -71,8 +71,8 @@ Console::success('Finished warmup in '.$warmupTime.' seconds'); * + pass one-time api key * 4. Update execution status - DONE * 5. Update execution stdout & stderr - DONE - * 6. Trigger audit log - * 7. Trigger usage log + * 6. Trigger audit log - DONE + * 7. Trigger usage log - DONE */ //TODO aviod scheduled execution if delay is bigger than X offest @@ -90,13 +90,10 @@ Console::success('Finished warmup in '.$warmupTime.' seconds'); /** * Get Usage Stats * -> Network (docker stats --no-stream --format="{{.NetIO}}" appwrite) - * -> CPU Time - * -> Invoctions (+1) - * Report to usage worker + * -> CPU Time - DONE + * -> Invoctions (+1) - DONE */ -// Double-check Cleanup - class FunctionsV1 { public $args = [];