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

[5.x] Add ability to clear queues from dashboard #890

Closed
wants to merge 4 commits into from
Closed

[5.x] Add ability to clear queues from dashboard #890

wants to merge 4 commits into from

Conversation

paras-malhotra
Copy link
Contributor

@paras-malhotra paras-malhotra commented Sep 17, 2020

queues
confirm

This PR adds the ability to clear queues (delete all jobs from specific queues) from the Horizon dashboard.
Resubmission of #742 with fixes to sorted sets and also uses the in-built queue clear of the Laravel framework based on laravel/framework#34330. Fixes #328.

Important Notice
Clearing of queues will not work on Laravel versions below 8.4 (unreleased). So I'm not sure if we want to send to master or 5x? The illuminate\queue repository isn't updated with the recent changes either, so we can't bump up that version yet. Also, I haven't compiled assets with this PR. Let me know if you'd like me to update with compilation of assets as well.

@taylorotwell
Copy link
Member

It would probably be best to check for the existence of Illuminate\Foundation\Application and then read the VERSION constant from it to determine whether to show this in the UI.

@paras-malhotra
Copy link
Contributor Author

paras-malhotra commented Sep 17, 2020

Sure @taylorotwell, I think an even better way might be to check if the queue has the method clear. I'll update the PR accordingly.

@taylorotwell
Copy link
Member

Sure, either way.

@paras-malhotra
Copy link
Contributor Author

paras-malhotra commented Sep 17, 2020

@taylorotwell, I've added the check in the UI to display only if the clear method exists. Haven't committed freshly compiled assets as mentioned in the contribution guide.

return $this->getRecent($index === 0 ? null : $index * 50)->filter(function ($recent) use ($queue) {
return in_array($recent->status, ['pending', 'reserved']) && $recent->queue === $queue;
});
})->flatten(1)->pluck('id')->all();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain what this is doing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we're collecting the IDs of the pending or reserved jobs on the specified queue. To do so, we get all the recent jobs (50 at a time based on the in-built RedisJobRepository methods) and filter through them to check 1) if they're either pending or reserved and 2) if the queue matches the specified queue. On the filtered set of jobs, we pluck the job IDs and then delete them from the Redis hash and recent/pending jobs sorted sets.

@@ -5,6 +5,7 @@
Route::prefix('api')->group(function () {
// Dashboard Routes...
Route::get('/stats', 'DashboardStatsController@index')->name('horizon.stats.index');
Route::post('/clearQueue', 'QueueClearController')->name('horizon.queue-clear.store');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear to me why a delete operation would be a POST. Shouldn't it be something like DELETE /queues/{queue-name} or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of clearing queues as more of an action rather than deleting a resource. If you'd like I can change it to a delete operation.

@taylorotwell
Copy link
Member

Why don't we take this one step at a time. Why don't we have just a CLI command to clear queues in Horizon first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clear all jobs of one queue
2 participants