Skip to content

Commit

Permalink
feat: allow failure file env-var to prevent logging (#4982)
Browse files Browse the repository at this point in the history
addresses #3832
  • Loading branch information
bshaffer authored Jan 27, 2022
1 parent 48cf3a9 commit eacb8a1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Core/src/Batch/HandleFailureTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ trait HandleFailureTrait
private function initFailureFile()
{
$this->baseDir = getenv('GOOGLE_CLOUD_BATCH_DAEMON_FAILURE_DIR');

if ('false' === $this->baseDir) {
// setting the file to the string "false" will prevent logging of failed items
return;
}

if ($this->baseDir === false) {
$this->baseDir = sprintf(
'%s/batch-daemon-failure',
Expand Down Expand Up @@ -80,9 +86,11 @@ public function handleFailure($idNum, array $items)
$this->initFailureFile();
}

$fp = @fopen($this->failureFile, 'a');
@fwrite($fp, serialize([$idNum => $items]) . PHP_EOL);
@fclose($fp);
if ($this->failureFile) {
$fp = @fopen($this->failureFile, 'a');
@fwrite($fp, serialize([$idNum => $items]) . PHP_EOL);
@fclose($fp);
}
}

/**
Expand Down

0 comments on commit eacb8a1

Please sign in to comment.