Class: ActiveJob::JobProxy

Inherits:
Base
  • Object
show all
Defined in:
lib/active_job/job_proxy.rb

Overview

A proxy for managing jobs without having to load the corresponding job class.

This is useful for managing jobs without having the job classes present in the code base.

Defined Under Namespace

Classes: UnsupportedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_data) ⇒ JobProxy

Returns a new instance of JobProxy.



13
14
15
16
17
# File 'lib/active_job/job_proxy.rb', line 13

def initialize(job_data)
  super
  @job_class_name = job_data["job_class"]
  deserialize(job_data)
end

Instance Attribute Details

#filtered_raw_dataObject

Raw data with the sensitive user data filtered out.



11
12
13
# File 'lib/active_job/job_proxy.rb', line 11

def filtered_raw_data
  @filtered_raw_data
end

#job_class_nameObject (readonly)

Returns the value of attribute job_class_name.



9
10
11
# File 'lib/active_job/job_proxy.rb', line 9

def job_class_name
  @job_class_name
end

Instance Method Details

#durationObject



29
30
31
32
# File 'lib/active_job/job_proxy.rb', line 29

def duration
  ended_at = finished_at || failed_at
  ended_at - scheduled_at if ended_at && scheduled_at
end

#perform_nowObject

Raises:



25
26
27
# File 'lib/active_job/job_proxy.rb', line 25

def perform_now
  raise UnsupportedError, "A JobProxy doesn't support immediate execution, only enqueuing."
end

#serializeObject



19
20
21
22
23
# File 'lib/active_job/job_proxy.rb', line 19

def serialize
  super.tap do |json|
    json["job_class"] = @job_class_name
  end
end