From 408ae68e7a224289e89e9c2b741cacbb74516c1c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Mon, 14 Dec 2020 22:09:44 +0530 Subject: [PATCH] feat: starter for maintenance task --- Dockerfile | 4 +++- app/cli.php | 1 + app/tasks/maintenance.php | 19 +++++++++++++++++++ bin/maintenance | 3 +++ docker-compose.yml | 16 ++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/tasks/maintenance.php create mode 100644 bin/maintenance diff --git a/Dockerfile b/Dockerfile index d41dbc50f..eccefed79 100755 --- a/Dockerfile +++ b/Dockerfile @@ -93,7 +93,8 @@ ENV _APP_SERVER=swoole \ _APP_FUNCTIONS_TIMEOUT=900 \ _APP_FUNCTIONS_CONTAINERS=10 \ _APP_SETUP=self-hosted \ - _APP_VERSION=$VERSION + _APP_VERSION=$VERSION \ + _APP_MAINTENANCE_INTERVAL=10 #ENV _APP_SMTP_SECURE '' #ENV _APP_SMTP_USERNAME '' #ENV _APP_SMTP_PASSWORD '' @@ -155,6 +156,7 @@ RUN mkdir -p /storage/uploads && \ # Executables RUN chmod +x /usr/local/bin/doctor && \ + chmod +x /usr/local/bin/maintenance && \ chmod +x /usr/local/bin/install && \ chmod +x /usr/local/bin/migrate && \ chmod +x /usr/local/bin/schedule && \ diff --git a/app/cli.php b/app/cli.php index 9c9989060..ced2fb8da 100644 --- a/app/cli.php +++ b/app/cli.php @@ -9,6 +9,7 @@ use Utopia\CLI\Console; $cli = new CLI(); include 'tasks/doctor.php'; +include 'tasks/maintenance.php'; include 'tasks/install.php'; include 'tasks/migrate.php'; include 'tasks/sdks.php'; diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php new file mode 100644 index 000000000..aa98662fa --- /dev/null +++ b/app/tasks/maintenance.php @@ -0,0 +1,19 @@ +task('maintenance') + ->desc('Schedules maintenance tasks and publishes them to resque') + ->action(function () { + $interval = App::getEnv('_APP_MAINTENANCE_INTERVAL', ''); + + for($i = 0; $i <= 10; ++$i){ + Console::log('Starting the maintenance worker every '.$interval.' seconds'); + sleep($interval); + } + + }); \ No newline at end of file diff --git a/bin/maintenance b/bin/maintenance new file mode 100644 index 000000000..099551cb3 --- /dev/null +++ b/bin/maintenance @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php maintenance $@ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 72d791fa9..5cd694188 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -277,6 +277,22 @@ services: - _APP_SMTP_USERNAME - _APP_SMTP_PASSWORD + appwrite-maintenance: + entrypoint: maintenance + container_name: appwrite-maintenance + build: + context: . + restart: unless-stopped + networks: + - appwrite + depends_on: + - redis + - mariadb + environment: + - _APP_ENV + - _APP_REDIS_HOST + - _APP_REDIS_PORT + appwrite-schedule: entrypoint: schedule container_name: appwrite-schedule