Skip to content

Commit

Permalink
fix check deleting failed job is actually failed (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
hxnk authored Sep 23, 2020
1 parent 09173d9 commit f537643
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Repositories/RedisJobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,9 @@ public function storeRetryReference($id, $retryId)
*/
public function deleteFailed($id)
{
$this->connection()->zrem('failed_jobs', $id);

$this->connection()->del($id);
return $this->connection()->zrem('failed_jobs', $id) != 1
? 0
: $this->connection()->del($id);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/RedisJobRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,30 @@ public function test_it_removes_recent_jobs_when_queue_is_purged()
$this->assertNotNull($recent->firstWhere('id', 2));
$this->assertCount(2, $repository->getJobs([1, 2, 3, 4, 5]));
}

public function test_it_will_delete_a_failed_job()
{
$repository = $this->app->make(JobRepository::class);
$payload = new JobPayload(json_encode(['id' => 1, 'displayName' => 'foo']));

$repository->failed(new Exception('Failed Job'), 'redis', 'default', $payload);

$result = $repository->deleteFailed(1);

$this->assertSame(1, $result);
$this->assertNull($repository->findFailed(1));
}

public function test_it_will_not_delete_a_job_if_the_job_has_not_failed()
{
$repository = $this->app->make(JobRepository::class);
$payload = new JobPayload(json_encode(['id' => 1, 'displayName' => 'foo']));

$repository->pushed('redis', 'default', $payload);

$result = $repository->deleteFailed(1);

$this->assertSame(0, $result);
$this->assertSame('1', $repository->getRecent()[0]->id);
}
}

0 comments on commit f537643

Please sign in to comment.