Skip to content

Commit

Permalink
Add Requeue/Reject handling
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed Apr 5, 2022
1 parent 8f7ab4e commit a90f87b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 42 deletions.
54 changes: 27 additions & 27 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/Application/Processor/Handler/PackageDiscoveryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
* - List of required dependencies per version
* - Package statistics
*/
public function __invoke(CommandInterface $command): HandlerResultEnum {
public function __invoke(CommandInterface $command, array $attributes = []): HandlerResultEnum {
static $lastPackage = '';
static $lastTimestamp = 0;
try {
Expand All @@ -67,7 +67,7 @@ public function __invoke(CommandInterface $command): HandlerResultEnum {
$lastPackage === $packageName &&
time() - $lastTimestamp < 10
) {
$this->logger->info(
$this->logger->debug(
'Package discovery handler: Skipping duplicated job',
[
'package' => $packageName,
Expand Down Expand Up @@ -261,8 +261,8 @@ static function (string $key): bool {
}

// update deduplication guards
$lastPackage = $packageName;
$lastTimestamp = time();
$lastPackage = $packageName;
$lastTimestamp = ($attributes['timestamp'] ?? new DateTimeImmutable())->getTimestamp();

return HandlerResultEnum::Accept;
} catch (Exception $exception) {
Expand All @@ -278,6 +278,11 @@ static function (string $key): bool {
]
);

// reject a command that has been requeued
if ($attributes['isRedelivery'] ?? false) {
return HandlerResultEnum::Reject;
}

return HandlerResultEnum::Requeue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
/**
* Updates all dependency references that "require" or "require-dev" $package
*/
public function __invoke(CommandInterface $command): HandlerResultEnum {
public function __invoke(CommandInterface $command, array $attributes = []): HandlerResultEnum {
static $lastPackage = '';
static $lastTimestamp = 0;
try {
Expand All @@ -47,7 +47,7 @@ public function __invoke(CommandInterface $command): HandlerResultEnum {
$lastPackage === $packageName &&
time() - $lastTimestamp < 10
) {
$this->logger->info(
$this->logger->debug(
'Update dependency status handler: Skipping duplicated job',
[
'package' => $packageName,
Expand Down Expand Up @@ -98,8 +98,8 @@ public function __invoke(CommandInterface $command): HandlerResultEnum {
}

// update deduplication guards
$lastPackage = $packageName;
$lastTimestamp = time();
$lastPackage = $packageName;
$lastTimestamp = ($attributes['timestamp'] ?? new DateTimeImmutable())->getTimestamp();

return HandlerResultEnum::Accept;
} catch (Exception $exception) {
Expand All @@ -115,6 +115,11 @@ public function __invoke(CommandInterface $command): HandlerResultEnum {
]
);

// reject a command that has been requeued
if ($attributes['isRedelivery'] ?? false) {
return HandlerResultEnum::Reject;
}

return HandlerResultEnum::Requeue;
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/Application/Processor/Handler/UpdateVersionStatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
/**
* Updates the version status that requires $dependency
*/
public function __invoke(CommandInterface $command): HandlerResultEnum {
public function __invoke(CommandInterface $command, array $attributes = []): HandlerResultEnum {
static $lastDependency = '';
static $lastTimestamp = 0;
try {
Expand All @@ -53,7 +53,7 @@ public function __invoke(CommandInterface $command): HandlerResultEnum {
$lastDependency === $dependencyName &&
time() - $lastTimestamp < 10
) {
$this->logger->info(
$this->logger->debug(
'Update version status handler: Skipping duplicated job',
[
'dependency' => $dependencyName,
Expand Down Expand Up @@ -106,7 +106,7 @@ static function (Dependency $dependency): DependencyStatusEnum {

// update deduplication guards
$lastDependency = $dependencyName;
$lastTimestamp = time();
$lastTimestamp = ($attributes['timestamp'] ?? new DateTimeImmutable())->getTimestamp();

return HandlerResultEnum::Accept;
} catch (Exception $exception) {
Expand All @@ -122,6 +122,11 @@ static function (Dependency $dependency): DependencyStatusEnum {
]
);

// reject a command that has been requeued
if ($attributes['isRedelivery'] ?? false) {
return HandlerResultEnum::Reject;
}

return HandlerResultEnum::Requeue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(ProducerInterface $producer, LoggerInterface $logger
/**
* update the version status that requires $dependency
*/
public function __invoke(EventInterface $event): void {
public function __invoke(EventInterface $event, array $attributes = []): void {
$dependency = $event->getDependency();
$this->logger->debug(
'Dependency updated',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(ProducerInterface $producer, LoggerInterface $logger
$this->logger = $logger;
}

public function __invoke(EventInterface $event): void {
public function __invoke(EventInterface $event, array $attributes = []): void {
$package = $event->getPackage();
$this->logger->debug(
'Package created',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(ProducerInterface $producer, LoggerInterface $logger
}


public function __invoke(EventInterface $event): void {
public function __invoke(EventInterface $event, array $attributes = []): void {
$package = $event->getPackage();
$this->logger->debug(
'Package updated',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
*
* Note: only sets the latest version if it is stable
*/
public function __invoke(EventInterface $event): void {
public function __invoke(EventInterface $event, array $attributes = []): void {
$version = $event->getVersion();
$this->logger->debug(
'Version created',
Expand Down

0 comments on commit a90f87b

Please sign in to comment.