diff --git a/app/console b/app/console index 3a0c8f0334..b981302dee 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 3a0c8f0334d402a6e27c8b5c0512f3d60080ddbd +Subproject commit b981302dee30eab33e155af79f0088822b29a2b6 diff --git a/app/http.php b/app/http.php index 23fd0dbcc9..2978eee51f 100644 --- a/app/http.php +++ b/app/http.php @@ -89,7 +89,6 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { try { $cache = $app->getResource('cache'); /** @var Utopia\Cache\Cache $cache */ - $cache->flush(); Console::success('[Setup] - Creating database: appwrite...'); $dbForConsole->create(); } catch (\Exception $e) { diff --git a/app/workers/functions.php b/app/workers/functions.php index ff8d9a509d..453188936f 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -265,8 +265,7 @@ $server->job() while ($sum >= $limit) { $functions = $dbForProject->find('functions', [ Query::limit($limit), - Query::offset($offset), - Query::orderAsc('name'), + Query::offset($offset) ]); $sum = \count($functions); @@ -278,7 +277,15 @@ $server->job() if (!array_intersect($events, $function->getAttribute('events', []))) { continue; } - Console::success('Iterating function: ' . $function->getAttribute('name')); + + /** Skip if a function has been triggered by its own execution */ + $event = "functions.{$function->getId()}.executions.*"; + if (in_array($event, $events)) { + Console::warning("Skipping function: {$function->getAttribute('name')} from project: {$project->getId()} triggered by self"); + continue; + } + + Console::success("Iterating function: {$function->getAttribute('name')} from project: {$project->getId()}"); $execute( log: $log, statsd: $statsd, diff --git a/src/Appwrite/Event/Validator/Event.php b/src/Appwrite/Event/Validator/Event.php index 4bf501f2d3..3f22900486 100644 --- a/src/Appwrite/Event/Validator/Event.php +++ b/src/Appwrite/Event/Validator/Event.php @@ -7,6 +7,11 @@ use Utopia\Validator; class Event extends Validator { + /** + * @var string + */ + protected string $message = 'Event is not valid.'; + /** * Get Description. * @@ -16,7 +21,7 @@ class Event extends Validator */ public function getDescription(): string { - return 'Event is not valid.'; + return $this->message; } /** @@ -40,6 +45,12 @@ class Event extends Validator * Identify all sections of the pattern. */ $type = $parts[0] ?? false; + + if ($type == 'functions') { + $this->message = 'Triggering a function on a function event is not allowed.'; + return false; + } + $resource = $parts[1] ?? false; $hasSubResource = $count > 3 && ($events[$type]['$resource'] ?? false) && ($events[$type][$parts[2]]['$resource'] ?? false); $hasSubSubResource = $count > 5 && $hasSubResource && ($events[$type][$parts[2]][$parts[4]]['$resource'] ?? false);