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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Illuminate/Queue/Failed/DynamoDbFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,28 @@ class DynamoDbFailedJobProvider implements FailedJobProviderInterface
*/
protected $table;

/**
* The number of days a failed job should be retained.
*
* @var string
*/
protected $expireDays;
Comment on lines +35 to +40
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;


/**
* 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

* @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)

{
$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;

}

/**
Expand Down Expand Up @@ -72,7 +81,7 @@ public function log($connection, $queue, $payload, $exception)
'payload' => ['S' => $payload],
'exception' => ['S' => (string) $exception],
'failed_at' => ['N' => (string) $failedAt->getTimestamp()],
'expires_at' => ['N' => (string) $failedAt->addDays(3)->getTimestamp()],
'expires_at' => ['N' => (string) $failedAt->addDays($this->expireDays)->getTimestamp()],
],
]);

Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Queue/QueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

);
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Queue/DynamoDbFailedJobProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);


$provider->log('connection', 'queue', json_encode(['uuid' => (string) $uuid]), $exception);

Expand Down Expand Up @@ -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);


$response = $provider->all();

Expand Down Expand Up @@ -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);


$response = $provider->find('id');

Expand Down Expand Up @@ -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);


$response = $provider->find('id');

Expand All @@ -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);


$provider->forget('id');
}
Expand Down
Loading