Skip to content

Commit

Permalink
Merge pull request #2 from apacheborys/bug/file-transport-undefined-i…
Browse files Browse the repository at this point in the history
…ndex-in-howManyTries-method

Bug/file transport undefined index in how many tries method
  • Loading branch information
apacheborys authored Jan 22, 2023
2 parents 648e6b7 + 03f7a2c commit 1a2ff80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/BasicExecutor/CommandExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ApacheBorys\Retry\Entity\Config;
use ApacheBorys\Retry\Entity\Message;
use ApacheBorys\Retry\Interfaces\Executor;
use Throwable;

class CommandExecutor implements Executor
{
Expand Down Expand Up @@ -67,7 +68,7 @@ public function handle(Message $message): bool
}

$returnValue = proc_close($process);
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->rollbackEnvironmentVariables();

throw $e;
Expand All @@ -79,26 +80,30 @@ public function handle(Message $message): bool
return $returnValue !== -1;
}

public function compilePayload(\Throwable $exception, Config $config): array
public function compilePayload(Throwable $exception, Config $config): array
{
$result = [];

foreach ($this->arguments as $argName => $argRegExp) {
preg_match($argRegExp, $exception->getMessage(), $matches);
if ($matches && isset($matches[0])) {
$result[$argName] = $matches[0];
$matches = [];

try {
preg_match($argRegExp, $exception->getMessage(), $matches);
} catch (Throwable $e) {
}

$result[$argName] = count($matches) > 0 ? $matches[0] : $argRegExp;
}

return $result;
}

public function getCorrelationId(\Throwable $exception, Config $config): string
public function getCorrelationId(Throwable $exception, Config $config): string
{
$id = getenv(self::ALIAS_FOR_CORRELATION_ID);

if (!$id) {
$config->getTransport()->getNextId($exception, $config);
$id = $config->getTransport()->getNextId($exception, $config);
}

return (string) $id;
Expand Down
2 changes: 1 addition & 1 deletion src/BasicExecutor/HttpExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getCorrelationId(\Throwable $exception, Config $config): string
$id = $_SERVER['HTTP_' . self::CID] ?? apache_request_headers()[self::CID] ?? null;

if (!$id) {
$config->getTransport()->getNextId($exception, $config);
$id = $config->getTransport()->getNextId($exception, $config);
}

return (string) $id;
Expand Down
2 changes: 1 addition & 1 deletion src/BasicTransport/FileTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function howManyTriesWasBefore(\Throwable $exception, Config $config): in

$correlationId = $config->getExecutor()->getCorrelationId($exception, $config);

$keysFromIndex = array_keys($this->fileIndexPosition[$correlationId]);
$keysFromIndex = array_keys($this->fileIndexPosition[$correlationId] ?? []);

return isset($this->fileIndexPosition[$correlationId]) && count($keysFromIndex) > 0 ? max($keysFromIndex) : 0;
}
Expand Down

0 comments on commit 1a2ff80

Please sign in to comment.