diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a87f1e574f..385016db91 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ jobs: with: fetch-depth: 2 submodules: recursive - ref: master + ref: cl-1.4.x - name: Login to Docker Hub uses: docker/login-action@v2 diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 2861ae40c3..4c41c8bd34 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1708,7 +1708,8 @@ App::post('/v1/functions/:functionId/executions') path: $path, method: $method, headers: $headers, - runtimeEntrypoint: $command + runtimeEntrypoint: $command, + requestTimeout: 30 ); $headersFiltered = []; diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index c0ce213789..a01138225f 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -92,16 +92,17 @@ App::post('/v1/projects') $projectId = ($projectId == 'unique()') ? ID::unique() : $projectId; - $backups['database_db_fra1_02'] = ['from' => '7:30', 'to' => '8:15']; - $backups['database_db_fra1_03'] = ['from' => '10:30', 'to' => '11:15']; - $backups['database_db_fra1_04'] = ['from' => '13:30', 'to' => '14:15']; - $backups['database_db_fra1_05'] = ['from' => '4:30', 'to' => '5:15']; - $backups['database_db_fra1_06'] = ['from' => '16:30', 'to' => '17:15']; + $backups['database_db_fra1_v14x_02'] = ['from' => '7:30', 'to' => '8:15']; + $backups['database_db_fra1_v14x_03'] = ['from' => '10:30', 'to' => '11:15']; + $backups['database_db_fra1_v14x_04'] = ['from' => '13:30', 'to' => '14:15']; + $backups['database_db_fra1_v14x_05'] = ['from' => '4:30', 'to' => '5:15']; + $backups['database_db_fra1_v14x_06'] = ['from' => '16:30', 'to' => '17:15']; + $backups['database_db_fra1_v14x_07'] = ['from' => '19:30', 'to' => '20:15']; $databases = Config::getParam('pools-database', []); /** - * Extract db from list while backing + * Remove databases from the list that are currently undergoing an backup */ if (count($databases) > 1) { $now = new \DateTime(); @@ -120,7 +121,9 @@ App::post('/v1/projects') } } - if ($index = array_search('database_db_fra1_06', $databases)) { + $databaseOverride = App::getEnv('_APP_DATABASE_OVERRIDE', null); + $index = array_search($databaseOverride, $databases); + if ($index) { $database = $databases[$index]; } else { $database = $databases[array_rand($databases)]; diff --git a/app/controllers/general.php b/app/controllers/general.php index b2b3d37471..bc21da50dd 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -139,6 +139,7 @@ function router(App $utopia, Database $dbForConsole, SwooleRequest $swooleReques \curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // \curl_setopt($ch, CURLOPT_HEADER, true); \curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + \curl_setopt($ch, CURLOPT_TIMEOUT, 30); $executionResponse = \curl_exec($ch); $statusCode = \curl_getinfo($ch, CURLINFO_HTTP_CODE); diff --git a/src/Appwrite/Platform/Tasks/Hamster.php b/src/Appwrite/Platform/Tasks/Hamster.php index 5b04c338eb..1d5d3b0b26 100644 --- a/src/Appwrite/Platform/Tasks/Hamster.php +++ b/src/Appwrite/Platform/Tasks/Hamster.php @@ -97,6 +97,32 @@ class Hamster extends Action /** Get Project Name */ $statsPerProject['project_name'] = $project->getAttribute('name'); + /** Total Project Variables */ + $statsPerProject['custom_variables'] = $dbForProject->count('variables', [], APP_LIMIT_COUNT); + + /** Total Migrations */ + $statsPerProject['custom_migrations'] = $dbForProject->count('migrations', [], APP_LIMIT_COUNT); + + /** Get Custom SMTP */ + $smtp = $project->getAttribute('smtp', null); + if ($smtp) { + $statsPerProject['custom_smtp_status'] = $smtp['enabled'] === true ? 'enabled' : 'disabled'; + + /** Get Custom Templates Count */ + $templates = array_keys($project->getAttribute('templates', [])); + $statsPerProject['custom_email_templates'] = array_filter($templates, function ($template) { + return str_contains($template, 'email'); + }); + $statsPerProject['custom_sms_templates'] = array_filter($templates, function ($template) { + return str_contains($template, 'sms'); + }); + } + + /** Get total relationship attributes */ + $statsPerProject['custom_relationship_attributes'] = $dbForProject->count('attributes', [ + Query::equal('type', ['relationship']) + ], APP_LIMIT_COUNT); + /** Get Total Functions */ $statsPerProject['custom_functions'] = $dbForProject->count('functions', [], APP_LIMIT_COUNT); @@ -108,6 +134,17 @@ class Hamster extends Action /** Get Total Deployments */ $statsPerProject['custom_deployments'] = $dbForProject->count('deployments', [], APP_LIMIT_COUNT); + $statsPerProject['custom_deployments_manual'] = $dbForProject->count('deployments', [ + Query::equal('type', ['manual']) + ], APP_LIMIT_COUNT); + $statsPerProject['custom_deployments_git'] = $dbForProject->count('deployments', [ + Query::equal('type', ['vcs']) + ], APP_LIMIT_COUNT); + + /** Get VCS repos connected */ + $statsPerProject['custom_vcs_repositories'] = $dbForConsole->count('repositories', [ + Query::equal('projectInternalId', [$project->getInternalId()]) + ], APP_LIMIT_COUNT); /** Get Total Teams */ $statsPerProject['custom_teams'] = $dbForProject->count('teams', [], APP_LIMIT_COUNT); @@ -132,19 +169,16 @@ class Hamster extends Action throw new Exception('Membership not found. Skipping project : ' . $project->getId()); } - $userInternalId = $membership->getAttribute('userInternalId', null); - if ($userInternalId) { - $user = $dbForConsole->findOne('users', [ - Query::equal('_id', [$userInternalId]), - ]); - + $userId = $membership->getAttribute('userId', null); + if ($userId) { + $user = $dbForConsole->getDocument('users', $userId); $statsPerProject['email'] = $user->getAttribute('email', null); $statsPerProject['name'] = $user->getAttribute('name', null); } } /** Get Domains */ - $statsPerProject['custom_domains'] = $dbForConsole->count('domains', [ + $statsPerProject['custom_domains'] = $dbForConsole->count('rules', [ Query::equal('projectInternalId', [$project->getInternalId()]), Query::limit(APP_LIMIT_COUNT) ]); @@ -234,15 +268,16 @@ class Hamster extends Action if (!$res) { Console::error('Failed to create user profile for project: ' . $project->getId()); } + } - $event = new Event(); - $event - ->setName('Project Daily Usage') - ->setProps($statsPerProject); - $res = $this->mixpanel->createEvent($event); - if (!$res) { - Console::error('Failed to create event for project: ' . $project->getId()); - } + $event = new Event(); + $event + ->setName('Project Daily Usage') + ->setProps($statsPerProject); + $res = $this->mixpanel->createEvent($event); + + if (!$res) { + Console::error('Failed to create event for project: ' . $project->getId()); } } catch (Exception $e) { Console::error('Failed to send stats for project: ' . $project->getId()); @@ -362,12 +397,9 @@ class Hamster extends Action throw new Exception('Membership not found. Skipping organization : ' . $document->getId()); } - $userInternalId = $membership->getAttribute('userInternalId', null); - if ($userInternalId) { - $user = $dbForConsole->findOne('users', [ - Query::equal('_id', [$userInternalId]), - ]); - + $userId = $membership->getAttribute('userId', null); + if ($userId) { + $user = $dbForConsole->getDocument('users', $userId); $statsPerOrganization['email'] = $user->getAttribute('email', null); } diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index adc3b48b69..c7388069a1 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -177,6 +177,7 @@ class Executor string $method, array $headers, string $runtimeEntrypoint = null, + int $requestTimeout = null ) { if (empty($headers['host'])) { $headers['host'] = App::getEnv('_APP_DOMAIN', ''); @@ -204,9 +205,11 @@ class Executor // Safety timeout. Executor has timeout, and open runtime has soft timeout. // This one shouldn't really happen, but prevents from unexpected networking behaviours. - $timeout = $timeout + 15; + if ($requestTimeout == null) { + $requestTimeout = $timeout + 15; + } - $response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $timeout); + $response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $requestTimeout); $status = $response['headers']['status-code']; if ($status >= 400) {