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

[3.x] Revert filtering by tag #741

Merged
merged 3 commits into from
Jan 9, 2020
Merged
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
2 changes: 1 addition & 1 deletion public/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/app.js": "/app.js?id=dbc6b1d1957be6dae833",
"/app.js": "/app.js?id=2da3353561359e51b73b",
"/app.css": "/app.css?id=b95d548aba488172f4b4",
"/app-dark.css": "/app-dark.css?id=b5b064c2f5a4b673a1c5"
}
18 changes: 1 addition & 17 deletions resources/js/screens/recentJobs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/
data() {
return {
tagSearchPhrase: '',
searchTimeout: null,
ready: false,
loadingNewEntries: false,
hasNewEntries: false,
Expand Down Expand Up @@ -46,16 +44,6 @@
this.page = 1;

this.loadJobs(this.$route.params.tag);
},

tagSearchPhrase() {
clearTimeout(this.searchTimeout);
clearInterval(this.interval);

this.searchTimeout = setTimeout(() => {
this.loadJobs();
this.refreshJobsPeriodically();
}, 500);
}
},

Expand All @@ -69,9 +57,7 @@
this.ready = false;
}

var tagQuery = this.tagSearchPhrase ? 'tag=' + this.tagSearchPhrase + '&' : '';

this.$http.get('/' + Horizon.path + '/api/jobs/recent?' + tagQuery + 'starting_at=' + starting + '&limit=' + this.perPage)
this.$http.get('/' + Horizon.path + '/api/jobs/recent?starting_at=' + starting + '&limit=' + this.perPage)
.then(response => {
if (!this.$root.autoLoadsNewEntries && refreshing && this.jobs.length && _.first(response.data.jobs).id !== _.first(this.jobs).id) {
this.hasNewEntries = true;
Expand Down Expand Up @@ -144,8 +130,6 @@
<div class="card">
<div class="card-header d-flex align-items-center justify-content-between">
<h5>Recent Jobs</h5>

<input type="text" class="form-control" v-model="tagSearchPhrase" placeholder="Search Tags" style="width:200px">
</div>

<div v-if="!ready" class="d-flex align-items-center justify-content-center card-bg-secondary p-5 bottom-radius">
Expand Down
1 change: 0 additions & 1 deletion src/EventMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ trait EventMap
Events\JobPushed::class => [
Listeners\StoreJob::class,
Listeners\StoreMonitoredTags::class,
Listeners\StoreTagsForRecentJob::class,
],

Events\JobReserved::class => [
Expand Down
70 changes: 6 additions & 64 deletions src/Http/Controllers/RecentJobsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Http\Request;
use Laravel\Horizon\Contracts\JobRepository;
use Laravel\Horizon\Contracts\TagRepository;

class RecentJobsController extends Controller
{
Expand All @@ -15,26 +14,17 @@ class RecentJobsController extends Controller
*/
public $jobs;

/**
* The tag repository implementation.
*
* @var \Laravel\Horizon\Contracts\TagRepository
*/
public $tags;

/**
* Create a new controller instance.
*
* @param \Laravel\Horizon\Contracts\JobRepository $jobs
* @param \Laravel\Horizon\Contracts\TagRepository $tags
* @return void
*/
public function __construct(JobRepository $jobs, TagRepository $tags)
public function __construct(JobRepository $jobs)
{
parent::__construct();

$this->jobs = $jobs;
$this->tags = $tags;
}

/**
Expand All @@ -45,63 +35,15 @@ public function __construct(JobRepository $jobs, TagRepository $tags)
*/
public function index(Request $request)
{
$jobs = ! $request->query('tag')
? $this->paginate($request)
: $this->paginateByTag($request, $request->query('tag'));
$jobs = $this->jobs->getRecent($request->query('starting_at', -1))->map(function ($job) {
$job->payload = json_decode($job->payload);

$total = $request->query('tag')
? $this->tags->count('recent:'.$request->query('tag'))
: $this->jobs->countRecent();
return $job;
})->values();

return [
'jobs' => $jobs,
'total' => $total,
'total' => $this->jobs->countRecent(),
];
}

/**
* Paginate the recent jobs for the request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Support\Collection
*/
protected function paginate(Request $request)
{
return $this->jobs->getRecent($request->query('starting_at', -1))->map(function ($job) {
return $this->decode($job);
})->values();
}

/**
* Paginate the recent jobs for the request and tag.
*
* @param \Illuminate\Http\Request $request
* @param string $tag
* @return \Illuminate\Support\Collection
*/
protected function paginateByTag(Request $request, $tag)
{
$jobIds = $this->tags->paginate(
'recent:'.$tag, $request->query('starting_at', -1) + 1, 50
);

$startingAt = $request->query('starting_at', 0);

return $this->jobs->getJobs($jobIds, $startingAt)->map(function ($job) {
return $this->decode($job);
});
}

/**
* Decode the given job.
*
* @param object $job
* @return object
*/
protected function decode($job)
{
$job->payload = json_decode($job->payload);

return $job;
}
}
46 changes: 0 additions & 46 deletions src/Listeners/StoreTagsForRecentJob.php

This file was deleted.

24 changes: 0 additions & 24 deletions tests/Feature/QueueProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Redis;
use Laravel\Horizon\Contracts\JobRepository;
use Laravel\Horizon\Contracts\TagRepository;
use Laravel\Horizon\Events\JobReserved;
use Laravel\Horizon\Events\JobsMigrated;
use Laravel\Horizon\Tests\IntegrationTest;
Expand Down Expand Up @@ -94,27 +93,4 @@ public function test_stale_reserved_jobs_are_marked_as_pending_after_migrating()

$this->assertSame('pending', $status);
}

public function test_tags_for_recent_jobs_are_stored_in_redis()
{
$id = Queue::push(new Jobs\BasicJob);
$this->work();
$tags = resolve(TagRepository::class);
$ids = $tags->jobs('recent:first');
$this->assertEquals([$id], $ids);
$ids = $tags->jobs('recent:second');
$this->assertEquals([$id], $ids);
}

public function test_recent_job_tags_have_an_expiration()
{
Queue::push(new Jobs\BasicJob);
$this->work();
$ttl = Redis::connection('horizon')->pttl('recent:first');
$this->assertNotNull($ttl);
$this->assertGreaterThan(0, $ttl);
$ttl = Redis::connection('horizon')->pttl('recent:second');
$this->assertNotNull($ttl);
$this->assertGreaterThan(0, $ttl);
}
}