Skip to content

Commit

Permalink
Improve lock handling defaults (ubccr#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
smgallo authored and ryanrath committed Jul 24, 2017
1 parent 3531c25 commit 24362b6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions classes/ETL/LockFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ class LockFile extends Loggable
protected $lockDir = null;

/**
* Optional prefix for lock files, read from the configuration file
* Prefix for lock files. This is set to a reasonable default initially, but can be
* overriden by passing a value to the constructor. Pass an empty string for no
* prefix.
*
* @var string|null
* @var string
*/

protected $lockFilePrefix = null;
protected $lockFilePrefix = 'etlv2_';

/**
* File handle to the current lockfile
Expand Down Expand Up @@ -70,13 +72,16 @@ public function __construct($lockDir, $lockPrefix = null, Log $logger = null)
parent::__construct($logger);

if ( null === $lockDir || "" === $lockDir ) {
$lockDir = getcwd();
$this->logger->info("Empty lock directory specified, using current directory: $lockDir");
$lockDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'xdmod';
$this->logger->info("Empty lock directory specified, using temp directory: $lockDir");
}

$this->lockDir = $lockDir;
$this->pid = getmypid();
$this->lockFilePrefix = $lockPrefix;

if ( null !== $lockPrefix ) {
$this->lockFilePrefix = $lockPrefix;
}

if ( ! is_dir($this->lockDir) ) {
$this->logger->info("Creating lock directory '" . $this->lockDir . "'");
Expand Down Expand Up @@ -104,7 +109,7 @@ protected function generateLockfileName($pid = null)
return sprintf(
'%s/%s%d',
$this->lockDir,
( null !== $this->lockFilePrefix ? $this->lockFilePrefix : "" ),
$this->lockFilePrefix,
( null !== $pid ? $pid : $this->pid )
);
} // generateLockfileName()
Expand Down Expand Up @@ -138,8 +143,8 @@ public function lock(array $actionList)
while ( ($file = readdir($dh) ) !== false ) {
if ( '.' == $file || '..' == $file ) {
continue;
} elseif ( null !== $this->lockFilePrefix && 0 !== strpos($file, $this->lockFilePrefix) ) {
// If the prefix is set, the file must match the prefix
} elseif ( '' != $this->lockFilePrefix && 0 !== strpos($file, $this->lockFilePrefix) ) {
// If set, the file must match the prefix
continue;
}

Expand Down

0 comments on commit 24362b6

Please sign in to comment.