Module: Chronos::Integrations::ActiveJob::JobExtensions

Defined in:
lib/chronos/integrations/active_job.rb

Overview

Active Job instance hooks installed through Module#prepend.

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.notifierObject

Returns the value of attribute notifier.



83
84
85
# File 'lib/chronos/integrations/active_job.rb', line 83

def notifier
  @notifier
end

Instance Method Details

#deserialize(job_data) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/chronos/integrations/active_job.rb', line 97

def deserialize(job_data)
  result = super
  begin
    @chronos_context = Chronos::Integrations::ActiveJob.context(
      job_data.is_a?(Hash) ? (job_data[CONTEXT_KEY] || job_data[CONTEXT_KEY.to_sym]) : nil
    )
  rescue StandardError
    @chronos_context = {}
  end
  result
end

#perform_now(*arguments, &block) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/chronos/integrations/active_job.rb', line 109

def perform_now(*arguments, &block)
  context = @chronos_context || {}
  notifier = JobExtensions.notifier || Chronos
  return super if context.empty? || !notifier.respond_to?(:with_context)

  notifier.with_context(:context => context) { super }
end

#serialize(*arguments) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/chronos/integrations/active_job.rb', line 86

def serialize(*arguments)
  data = super
  begin
    envelope = Chronos::Integrations::ActiveJob.envelope(JobExtensions.notifier || Chronos)
    data[CONTEXT_KEY] = envelope if data.is_a?(Hash) && envelope
  rescue StandardError
    nil
  end
  data
end