Class: Flightdeck::ArgumentsPreview

Inherits:
Object
  • Object
show all
Defined in:
app/models/flightdeck/arguments_preview.rb

Overview

Turns a job's stored payload into the one part of it a list row wants: the actual job arguments.

What Solid Queue stores is the whole ActiveJob serialization — {"job_class":…,"job_id":…,"queue_name":…,"arguments":[…],…} — so a raw preview is almost entirely boilerplate that is identical on every row. The job detail page still shows the full payload, where it is genuinely useful.

The input is a byte prefix truncated by SQL, so the JSON is usually cut off mid-value. Parsing is lenient by design: extract what is there, and fall back to the raw prefix rather than showing nothing.

Constant Summary collapse

KEY =
/"arguments"\s*:\s*/
ELLIPSIS =
""

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ ArgumentsPreview

Returns a new instance of ArgumentsPreview.



23
24
25
# File 'app/models/flightdeck/arguments_preview.rb', line 23

def initialize(raw)
  @raw = raw.to_s
end

Class Method Details

.format(raw, length: 120) ⇒ Object



19
20
21
# File 'app/models/flightdeck/arguments_preview.rb', line 19

def self.format(raw, length: 120)
  new(raw).to_s(length: length)
end

Instance Method Details

#to_s(length: 120) ⇒ Object



27
28
29
30
31
32
# File 'app/models/flightdeck/arguments_preview.rb', line 27

def to_s(length: 120)
  value = extract
  return "" if value.blank?

  value.gsub(/\s+/, " ").strip.truncate(length, omission: ELLIPSIS)
end