diff --git a/bin/cron/import-and-build.php b/bin/cron/import-and-build.php index 702aad11..4a4096c5 100755 --- a/bin/cron/import-and-build.php +++ b/bin/cron/import-and-build.php @@ -2,23 +2,37 @@ run(function () { - $process = new Process( - command: ['/var/www/bin/console', 'app:strava:build-files'], - timeout: null - ); - $process->run(); + $processesToRun = [ + new Process(['/var/www/bin/console', 'app:strava:import-data']), + new Process(['/var/www/bin/console', 'app:strava:build-files']), + ]; - echo $process->getOutput(); + foreach ($processesToRun as $process) { + try { + $process->setTimeout(null); + $process->mustRun(); + echo $process->getOutput(); + } catch (ProcessFailedException $exception) { + echo $exception->getMessage(); + break; + } + } }) ->description('Import Strava data and build HTML files') - ->cron('* * * * *') + ->cron($cronExpression) ->preventOverlapping(); return $schedule; diff --git a/docker-compose.yml b/docker-compose.yml index d74cf3e7..ad8427d8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,7 @@ services: working_dir: /var/www environment: - PHP_CS_FIXER_IGNORE_ENV=true + - IMPORT_AND_BUILD_SCHEDULE=* * * * * profiles: - on-demand networks: diff --git a/docker/app/config/supervisord.conf b/docker/app/config/supervisord.conf index 50e7bd81..09470d83 100644 --- a/docker/app/config/supervisord.conf +++ b/docker/app/config/supervisord.conf @@ -13,6 +13,12 @@ stderr_logfile_maxbytes=0 autorestart=false startretries=0 +[program:cron] +command= sh -c "vendor/bin/crunz schedule:run && sleep 60" +directory=/var/www +autostart=true +autorestart=true + [program:nginx] command=nginx -g 'daemon off;' stdout_logfile=/dev/stdout diff --git a/src/Console/BuildStravaActivityFilesConsoleCommand.php b/src/Console/BuildStravaActivityFilesConsoleCommand.php index d5c29e78..a6681bbc 100644 --- a/src/Console/BuildStravaActivityFilesConsoleCommand.php +++ b/src/Console/BuildStravaActivityFilesConsoleCommand.php @@ -30,12 +30,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (!$this->migrationRunner->isAtLatestVersion()) { $output->writeln('Your database is not up to date with the migration schema. Run the import command before building the HTML files'); - return Command::SUCCESS; + return Command::FAILURE; } if (!$this->stravaDataImportStatus->isCompleted()) { $output->writeln('Wait until all Strava data has been imported before building the app'); - return Command::SUCCESS; + return Command::FAILURE; } $this->resourceUsage->startTimer(); diff --git a/src/Console/ImportStravaDataConsoleCommand.php b/src/Console/ImportStravaDataConsoleCommand.php index d7f018e9..2931b922 100644 --- a/src/Console/ImportStravaDataConsoleCommand.php +++ b/src/Console/ImportStravaDataConsoleCommand.php @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } catch (UnableToWriteFile|UnableToCreateDirectory) { $output->writeln('Make sure the container has write permissions to "storage/database" and "storage/files" on the host system'); - return Command::SUCCESS; + return Command::FAILURE; } $this->resourceUsage->startTimer();