Skip to content

[10.x] Make DynamoDB failed job provider countable #48178

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

Closed
wants to merge 2 commits into from
Closed
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: 12 additions & 1 deletion src/Illuminate/Queue/Failed/DynamoDbFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace Illuminate\Queue\Failed;

use Aws\DynamoDb\DynamoDbClient;
use Countable;
use DateTimeInterface;
use Exception;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;

class DynamoDbFailedJobProvider implements FailedJobProviderInterface
class DynamoDbFailedJobProvider implements FailedJobProviderInterface, Countable
{
/**
* The DynamoDB client instance.
Expand Down Expand Up @@ -162,6 +163,16 @@ public function forget($id)
return true;
}

/**
* Count the failed jobs.
*/
public function count(): int
{
return $this->dynamo->describeTable([
'TableName' => $this->table,
])['Table']['ItemCount'];
}

/**
* Flush all of the failed jobs from storage.
*
Expand Down
15 changes: 15 additions & 0 deletions tests/Queue/DynamoDbFailedJobProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,19 @@ public function testJobsCanBeDeleted()

$provider->forget('id');
}

public function testJobsCanBeCounted()
{
$dynamoDbClient = m::mock(DynamoDbClient::class);
$dynamoDbClient->shouldReceive('describeTable')->once()->with([
'TableName' => 'table',
])->andReturn([
'Table' => [
'ItemCount' => 5,
],
]);
$provider = new DynamoDbFailedJobProvider($dynamoDbClient, 'application', 'table');

$this->assertCount(5, $provider);
}
}