Skip to content

Commit

Permalink
Merge pull request #239 from quantcdn/fix/lockfile
Browse files Browse the repository at this point in the history
Set lockfile path specific to project name.
  • Loading branch information
stooit authored Jun 5, 2024
2 parents 197f315 + 90880e5 commit f01f991
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Commands/QuantDrushCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -76,13 +84,14 @@ private function getDrushPath() {
public function message($options = ['threads' => 5]) {
$this->output()->writeln("<info>Forking seed worker.</info>");
$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("<comment>Using drush binary at $drushPath. Override with \$DRUSH_PATH if required.</comment>");

// Bail if another run is in progress.
if (file_exists($lockFilePath)) {
$this->output()->writeln("<info>Seeding bailed. Another seed run is in progress.</info>");
$this->output()->writeln("<info>Seeding bailed. Another seed run is in progress (lockfile is present: {$lockFilePath})</info>");
$this->output()->writeln("<info>Run drush quant:unlock-queue to manually unlock the queue.</info>");
return;
}
else {
Expand Down Expand Up @@ -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.");
Expand Down

0 comments on commit f01f991

Please sign in to comment.