Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Adds support to allow specifying number of days to keep failed jobs in DynamoDB #54295

Open
wants to merge 2 commits into
base: 11.x
Choose a base branch
from

Conversation

j-fulbright
Copy link

This PR adds a new config option for queue.failed (when using DynamoDB): expire_days

This allows controlling the expires_at value for jobs that are inserted into DynamoDB, instead of the hardcoded value of 3. (Still defaulted to 3 in the absence of the config option)


This pull request introduces changes to the DynamoDbFailedJobProvider class to make the expiration period for failed jobs configurable. The main modifications include adding a new property for expiration days, updating the constructor to accept this new parameter, and adjusting the tests to accommodate this change.

Key changes:

Configuration of Expiration Days:

Service Provider Adjustment:

Test Updates:

Copy link
Contributor

@morloderex morloderex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property expireDays should be an integer, not a string.
Casting to an integer doesn't seem to be the correct approach here.
I have also defaulting the constructor argument to be the integer 3.

Let's wait for future feedback, as usually changing a constructor argument is considered a breaking change. So it might be better to add this additional configuration value through a getter and setter methods instead.

Comment on lines +35 to +40
/**
* The number of days a failed job should be retained.
*
* @var string
*/
protected $expireDays;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* The number of days a failed job should be retained.
*
* @var string
*/
protected $expireDays;
/**
* The number of days a failed job should be retained.
*
* @var int
*/
protected $expireDays;

{
$this->table = $table;
$this->dynamo = $dynamo;
$this->applicationName = $applicationName;
$this->expireDays = (int) $expireDays;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->expireDays = (int) $expireDays;
$this->expireDays = $expireDays;

@@ -324,7 +324,8 @@ protected function dynamoFailedJobProvider($config)
return new DynamoDbFailedJobProvider(
new DynamoDbClient($dynamoConfig),
$this->app['config']['app.name'],
$config['table']
$config['table'],
$config['expire_days'] ?? '3'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$config['expire_days'] ?? '3'
$config['expire_days'] ?? 3

@@ -47,7 +47,7 @@ public function testCanProperlyLogFailedJob()
],
]);

$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', 3);

@@ -83,7 +83,7 @@ public function testCanRetrieveAllFailedJobs()
],
]);

$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', 3);

@@ -124,7 +124,7 @@ public function testASingleJobCanBeFound()
],
]);

$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', 3);

@@ -152,7 +152,7 @@ public function testNullIsReturnedIfJobNotFound()
],
])->andReturn([]);

$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', 3);

@@ -171,7 +171,7 @@ public function testJobsCanBeDeleted()
],
])->andReturn([]);

$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', '3');
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table', 3);

* @return void
*/
public function __construct(DynamoDbClient $dynamo, $applicationName, $table)
public function __construct(DynamoDbClient $dynamo, $applicationName, $table, $expireDays)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function __construct(DynamoDbClient $dynamo, $applicationName, $table, $expireDays)
public function __construct(DynamoDbClient $dynamo, $applicationName, $table, $expireDays = 3)

/**
* Create a new DynamoDb failed job provider.
*
* @param \Aws\DynamoDb\DynamoDbClient $dynamo
* @param string $applicationName
* @param string $table
* @param string $expireDays
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param string $expireDays
* @param int $expireDays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants