Class: CanvasSync::Job

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

Overview

Inherit from this class to build a Job that will log to the canvas_sync_job_logs table

Instance Method Summary collapse

Instance Method Details

#create_job_log(job) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/canvas_sync/job.rb', line 51

def create_job_log(job)
  CanvasSync::JobLog.create(
    job_class: self.class.name,
    job_arguments: job.arguments,
    job_id: job.job_id,
    status: JobLog::ENQUEUED_STATUS,
  )
end

#report_checker_wait_timeObject



47
48
49
# File 'lib/canvas_sync/job.rb', line 47

def report_checker_wait_time
  Rails.env.development? ? 1.second : 30.seconds
end

#update_or_create_model(model, params) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/canvas_sync/job.rb', line 60

def update_or_create_model(model, params)
  if model.respond_to? :create_or_update
    model.create_or_update(params)
  elsif model.method_defined? :update_from_api_params!
    instance = model.find_or_initialize_by(canvas_id: params['id'])
    instance.update_from_api_params!(params)
    instance
  else
    raise "Could not create/update #{model.name}. It must have a create_or_update(params) ClassMethod or implement ApiSyncable."
  end
end