Skip to content

Commit

Permalink
Merge pull request #478 from driesvints/fix-find-failed
Browse files Browse the repository at this point in the history
[2.0] Fix findFailed method
  • Loading branch information
taylorotwell committed Jan 25, 2019
2 parents ec09d53 + 90fd47c commit 634771d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Repositories/RedisJobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,13 @@ public function findFailed($id)
$id, $this->keys
);

return is_array($attributes) && $attributes[0] !== null ? (object) array_combine($this->keys, $attributes) : null;
$job = is_array($attributes) && $attributes[0] !== null ? (object) array_combine($this->keys, $attributes) : null;

if ($job && $job->status !== 'failed') {
return null;
}

return $job;
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tests/Feature/RedisJobRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Laravel\Horizon\Tests\Feature;

use Exception;
use Laravel\Horizon\JobPayload;
use Laravel\Horizon\Tests\IntegrationTest;
use Laravel\Horizon\Contracts\JobRepository;

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

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

$this->assertEquals(1, $repository->findFailed(1)->id);
}

public function test_it_will_not_find_a_failed_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);

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

0 comments on commit 634771d

Please sign in to comment.