-
Notifications
You must be signed in to change notification settings - Fork 230
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
Unwrap ActiveJob job class in WebUI #460
Unwrap ActiveJob job class in WebUI #460
Conversation
This probably won't work.
This doesn't quite work though, the args are not correct for the ActiveJob wrapped one.
I got this by calling json.Marshal on a job that was rendered in the Web UI.
The Rails 5 case is probably not exactly correct, but the important thing for now is that it uses the correct wrapped job class.
@@ -415,6 +415,32 @@ func sortedLocaleNames(req *http.Request, fn func(string, bool)) { | |||
} | |||
} | |||
|
|||
func displayJobType(j *client.Job) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is based on https://github.com/sidekiq/sidekiq/blob/73c150d0430a8394cadb5cd49218895b113613a0/lib/sidekiq/api.rb#L374-L389. It handles regular ActiveJobs and also ActionMailer wrapped jobs, for Rails 5 and 6+.
I hope the error handling is reasonable, I think I got everything. I think that if it fails to get more specific info, it will fall back to the more general data. (E.g. if it can't get the mailer class info, it should revert to the job class, or the raw job.Type if nothing else fits.)
I do love how concise the Ruby is but it is kind of nice that the Go version forces you to handle possible errors if the data isn't in the shape that you expected. The nesting in Go seems kinda wild, not sure if there was a better way to write this.
} | ||
|
||
func makeActiveJob(jobType string) *client.Job { | ||
var payload = []byte(fmt.Sprintf(` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got these payloads by sticking this in my displayJobType
function:
out, err := json.Marshal(j)
if err == nil {
util.Infof("Job: %s", out)
}
So this should be exactly what the Web UI receives at render time. I parametrized certain things as made sense. I left the IDs and timestamps and whatnot alone since there's nothing particularly interesting in those.
|
||
func makeActionMailerJob(jobType string, mailerClass string, mailerMethod string) *client.Job { | ||
var payload = []byte(fmt.Sprintf(` | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the Job payload from a Rails 7.1 app. It seems to match the class in https://github.com/sidekiq/sidekiq/blob/73c150d0430a8394cadb5cd49218895b113613a0/test/api_test.rb#L34C135-L34C135, so I labeled it as Rails 6.x further down. I don't know if the specific fields are exactly the same as they would be in Rails 6, but for the purposes of getting the job type it doesn't matter.
expected: "FooJob", | ||
}, | ||
{ | ||
name: "Rails 5.x mailer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that in https://github.com/sidekiq/sidekiq/blob/73c150d0430a8394cadb5cd49218895b113613a0/test/api_test.rb#L30 the Rails 5 data is a bit smaller. Though I don't know if that's just because it doesn't include a serialized User object. In any case, for the purposes of this test the only difference is the job class, so I felt it was fine to use the same payload with different job classes for testing Rails 5 vs 6 handling.
Wow, this is great stuff. Well done, I'm impressed. |
Thanks! |
Unwraps ActiveJob job classes in the web UI.
This does not unwrap the arguments, but that would be a nice addition as well.
Based on similar logic from Sidekiq, thanks for the pointer @mperham! I barely understand Go so I hope the code is okay.
https://github.com/sidekiq/sidekiq/blob/73c150d0430a8394cadb5cd49218895b113613a0/lib/sidekiq/api.rb#L374-L389
Before:
After:
(This is from the "queue" page, which uses Type for the column, and apparently a darker font.)
Fixes #459