Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set lockfile path specific to project name. #239

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading