From 90880e5b9e6678a55ab29e67df859804a1db4463 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Wed, 5 Jun 2024 05:43:33 +0000 Subject: [PATCH] Set lockfile path specific to project name. Improve error output. --- src/Commands/QuantDrushCommands.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Commands/QuantDrushCommands.php b/src/Commands/QuantDrushCommands.php index d4cf343e..b37a0a40 100644 --- a/src/Commands/QuantDrushCommands.php +++ b/src/Commands/QuantDrushCommands.php @@ -27,6 +27,14 @@ class QuantDrushCommands extends DrushCommands { */ private $runningProcs = []; + /** + * Returns lock file location (project specific). + */ + private function getLockFileLocation() { + $config = \Drupal::configFactory()->getEditable('quant_api.settings'); + return sys_get_temp_dir() . '/' . $config->get('api_project') . '_quant_seed_worker.lock'; + } + /** * Returns path to drush binary for process forking. * @@ -76,13 +84,14 @@ private function getDrushPath() { public function message($options = ['threads' => 5]) { $this->output()->writeln("Forking seed worker."); $drushPath = $this->getDrushPath(); - $lockFilePath = sys_get_temp_dir() . '/quant_seed_worker.lock'; + $lockFilePath = $this->getLockFileLocation(); $cmd = $drushPath . ' queue:run quant_seed_worker'; $this->output()->writeln("Using drush binary at $drushPath. Override with \$DRUSH_PATH if required."); // Bail if another run is in progress. if (file_exists($lockFilePath)) { - $this->output()->writeln("Seeding bailed. Another seed run is in progress."); + $this->output()->writeln("Seeding bailed. Another seed run is in progress (lockfile is present: {$lockFilePath})"); + $this->output()->writeln("Run drush quant:unlock-queue to manually unlock the queue."); return; } else { @@ -118,7 +127,7 @@ public function message($options = ['threads' => 5]) { * @usage quant:unlock-queue */ public function unlock($options = []) { - $lockFilePath = sys_get_temp_dir() . '/quant_seed_worker.lock'; + $lockFilePath = $this->getLockFileLocation(); unlink($lockFilePath); $this->output()->writeln("Unlocked Quant queue.");