-
Notifications
You must be signed in to change notification settings - Fork 208
Description
Hey @rosa. Thanks for this gem all the work you've done with SolidQueue. We're transitioning our monolith from Resque to SolidQueue and it's been a great experience!
Just wondering if you would be interested in a feature similar to GoodJob's labelled jobs.
The problem
For us we have a need for something like this feature so that we can add team labels to jobs. Our Rails app is worked on by hundreds of developers and we have a concept of codeownership where each class is owned and maintained by a team and this concept is codified in our app. What we would really love to do is be able to filter jobs by teams. This would allow teams to triage their own jobs and it would generally make our lives easier. But this solution would be flexible enough that anyone could add their own labels or job metadata and filter jobs by these labels in the UI.
Proposed solution
The basic premise is there would be an active job extension (very similar to how concurrency_controls are implemented) that you could include in your job and then you can add a label to a specific job.
class ApplicationJob < ActiveJob::Base
include ActiveJob::Labels
end
# Add a default label to every job within the class
class WelcomeJob < ApplicationJob
self.job_labels = ["email"]
def perform
# Labels can be inspected from within the job
puts job_labels # => ["email"]
end
end
# Or add to individual jobs when enqueued
WelcomeJob.set(job_labels: ["email"]).perform_laterThis would then tie into Mission Control and we'd be able to filter jobs by these labels in the UI.
How Goodjob works is they store these labels in the database and essentially stamp jobs as they get enqueued with whatever labels are there at the time. This allows the UI to quickly filter and display these labels. For goodjob, because it's postgres, they store it as an array of text.
We could do something similar but I was kind of thinking of having a labels as it's own table? With unique label names. And then SolidQueue::Job would basically have the equivalent of a has_many :labels relationship and, when jobs are enqueued, we could essentially do a label.find_or_create_by(name: active_job.label). In reality it would have to be more efficient than this so that we don't slow down job enqueuing but that's the general idea.
Proposed table changes:
# add a label_id to solid_queue_jobs
change_table "solid_queue_jobs" do |t|
t.bigint "label_id", null: true
t.index ["label_id"], name: "index_solid_queue_label"
end
create_table "solid_queue_labels" do |t|
t.datetime "created_at", null: false
t.name, null: false, unique: true
t.index ["label"], name: "solid_queue_label_name"
endAnyway just throwing it out there. If this is something you would be interested in for solid_queue/mission control please let me know. I'd be happy to work on this feature and contribute back to both projects. Of course open to any feedback!
Thanks so much!