Class: Resque::Mcp::Models::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/mcp/models/job.rb

Overview

One job payload. Raw args are sealed — filtered access is the only public surface, so no caller can serialize them unfiltered.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name:, args:, queue: nil, run_at: nil) ⇒ Job

Returns a new instance of Job.



11
12
13
14
15
16
# File 'lib/resque/mcp/models/job.rb', line 11

def initialize(class_name:, args:, queue: nil, run_at: nil)
  @class_name = class_name
  @args = args
  @queue = queue
  @run_at = run_at
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



9
10
11
# File 'lib/resque/mcp/models/job.rb', line 9

def class_name
  @class_name
end

#queueObject (readonly)

Returns the value of attribute queue.



9
10
11
# File 'lib/resque/mcp/models/job.rb', line 9

def queue
  @queue
end

#run_atObject (readonly)

Returns the value of attribute run_at.



9
10
11
# File 'lib/resque/mcp/models/job.rb', line 9

def run_at
  @run_at
end

Instance Method Details

#as_json(_options = nil) ⇒ Object



51
52
53
54
# File 'lib/resque/mcp/models/job.rb', line 51

def as_json(_options = nil)
  {"class_name" => @class_name, "queue" => @queue, "run_at" => @run_at,
   "args" => filtered_args}
end

#filtered_argsObject

Key-based filtering runs here, before any presentation-layer truncation, so a secret can't survive inside a truncated JSON string. Each hash arg is filtered as its own root, so anchored dot-notation filters (/Acredit_card.code\z/) match exactly as in Rails log filtering. Only hash keys can match — bare positional scalars pass through. A raising host filter (e.g. a proc assuming string values) fails CLOSED: args are withheld with an in-band mark, never leaked.

Memoization assumes a Job never outlives its request (the adapter is per-request): the filter config and a transient fail-closed result are frozen in at first read. Revisit before ever caching adapter results across requests.



31
32
33
34
35
36
# File 'lib/resque/mcp/models/job.rb', line 31

def filtered_args
  return @filtered_args if defined?(@filtered_args)
  @filtered_args = filter(Resque::Mcp.config.param_filter, @args)
rescue => e
  @filtered_args = "[args withheld: filter_parameters raised #{e.class}]"
end

#inspectObject

Debug and generic-serialization surfaces must not undo the sealing: the default #inspect renders @args, ActiveSupport's Object#as_json/#to_json walk instance variables, and pp bypasses #inspect via #pretty_print.



42
43
44
45
# File 'lib/resque/mcp/models/job.rb', line 42

def inspect
  "#<#{self.class.name} class_name=#{@class_name.inspect} " \
    "queue=#{@queue.inspect} run_at=#{@run_at.inspect} args=[sealed]>"
end

#pretty_print(pp) ⇒ Object



47
48
49
# File 'lib/resque/mcp/models/job.rb', line 47

def pretty_print(pp)
  pp.text(inspect)
end