Class: CanvasSync::Jobs::CanvasProcessWaiter::InvokeCallbackWorker

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/canvas_sync/jobs/canvas_process_waiter.rb

Overview

This is a separate job so that, if it fails and a retry is triggered, it doesn’t query the API needlessly

Instance Method Summary collapse

Instance Method Details

#load_constant(const) ⇒ Object

rubocop:enable Metrics/PerceivedComplexity



67
68
69
70
# File 'lib/canvas_sync/jobs/canvas_process_waiter.rb', line 67

def load_constant(const)
  const = const.constantize if const.is_a?(String)
  const
end

#perform(job) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/canvas_sync/jobs/canvas_process_waiter.rb', line 37

def perform(job)
  job = job.symbolize_keys

  params = job[:args] || []
  params << job[:kwargs].symbolize_keys if job[:kwargs]
  # params[-1] = params[-1].symbolize_keys if params[-1].is_a?(Hash)

  if job[:model]
    model_class = load_constant(job[:model])
    find_by = job[:find_by]
    target = find_by.is_a?(Hash) ? model_class.find_by(find_by) : model_class.find_by(id: find_by)
    target.send(job[:method], *params)
  elsif job[:class]
    target = load_constant(job[:class])
    target.send(job[:method], *params)
  elsif job[:instance_of]
    target = load_constant(job[:instance_of]).new
    target.send(job[:method], *params)
  elsif job[:job]
    job_class = load_constant(job[:job])
    job_class = job_class.set(job[:options]) if job[:options].present?
    if job_class < ActiveJob::Base
      job_class.perform_later(*params)
    else
      job_class.perform_async(*params)
    end
  end
end