Class: Cyclid::API::Plugins::Worker::Local

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/cyclid/plugins/dispatcher/local.rb

Overview

Local Sidekiq based worker

Instance Method Summary collapse

Instance Method Details

#perform(job, job_id, callback_object) ⇒ Object

Run a job Runner asynchronously



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'app/cyclid/plugins/dispatcher/local.rb', line 139

def perform(job, job_id, callback_object)
  begin
    # Unserialize the callback object, if there is one
    callback = callback_object.nil? ? nil : Oj.load(callback_object)

    notifier = Notifier::Local.new(job_id, callback)
  rescue StandardError => ex
    Cyclid.logger.debug "couldn't create notifier: #{ex}"
    return false
  end

  begin
    runner = Cyclid::API::Job::Runner.new(job_id, job, notifier)
    success = runner.run
  rescue StandardError => ex
    Cyclid.logger.error "job runner failed: #{ex}"
    success = false
  end

  # Notify completion
  notifier.completion(success)

  return success
ensure
  ::ActiveRecord::Base.clear_active_connections!
end