Skip to content

Commit

Permalink
Simplification of job strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHash committed Aug 22, 2020
1 parent 02bac55 commit a214404
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 139 deletions.
66 changes: 33 additions & 33 deletions composer.lock

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

6 changes: 4 additions & 2 deletions src/Metadata/JobMetadataEnricher.php
Expand Up @@ -16,6 +16,8 @@

final class JobMetadataEnricher implements MetadataEnricherInterface
{
public const JOB = 'job';

private JobDefinitionMap $jobDefinitionMap;

private array $settings;
Expand All @@ -32,11 +34,11 @@ public function enrich(MetadataInterface $metadata): MetadataInterface

/** @var JobDefinitionInterface $jobDefinition */
$jobDefinition = $this->jobDefinitionMap->get($this->settings['job']);
$metadata = $metadata->with('job', $this->settings['job']);
$metadata = $metadata->with(self::JOB, $this->settings['job']);
foreach ($jobDefinition->getSettings() as $setting => $value) {
$metadata = $metadata->with($setting, $value);
}

return $metadata;
return $jobDefinition->getStrategy()->enrich($metadata);
}
}
16 changes: 0 additions & 16 deletions src/Strategy/Failure/FailureStrategyInterface.php

This file was deleted.

41 changes: 0 additions & 41 deletions src/Strategy/JobStrategy.php

This file was deleted.

7 changes: 2 additions & 5 deletions src/Strategy/JobStrategyInterface.php
Expand Up @@ -9,12 +9,9 @@
namespace Daikon\AsyncJob\Strategy;

use Daikon\MessageBus\EnvelopeInterface;
use Daikon\Metadata\MetadataEnricherInterface;

interface JobStrategyInterface
interface JobStrategyInterface extends MetadataEnricherInterface
{
public function getRetryInterval(EnvelopeInterface $envelope): ?int;

public function hasFailed(EnvelopeInterface $envelope): bool;

public function canRetry(EnvelopeInterface $envelope): bool;
}
26 changes: 26 additions & 0 deletions src/Strategy/NoRetry.php
@@ -0,0 +1,26 @@
<?php declare(strict_types=1);
/**
* This file is part of the daikon-cqrs/async-job project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Daikon\AsyncJob\Strategy;

use Daikon\AsyncJob\Strategy\JobStrategyInterface;
use Daikon\MessageBus\EnvelopeInterface;
use Daikon\Metadata\MetadataInterface;

class NoRetry implements JobStrategyInterface
{
public function canRetry(EnvelopeInterface $envelope): bool
{
return false;
}

public function enrich(MetadataInterface $metadata): MetadataInterface
{
return $metadata;
}
}
26 changes: 0 additions & 26 deletions src/Strategy/Retry/NoRetry.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Strategy/Retry/RetryStrategyInterface.php

This file was deleted.

0 comments on commit a214404

Please sign in to comment.