Sha256: 91727f7cbdbdf8df079e5e056bff5feda537d78296a9553b4e115978c253092b

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

class Marty::PromiseRubyJob < Struct.new(:promise,
                                         :title,
                                         :module_name,
                                         :method_name,
                                         :method_args,
                                         :hook,
                                        )

  def enqueue(job)
    config = Rails.configuration.marty
    hooks = config.promise_job_enqueue_hooks

    return if hooks.blank?

    hooks.each do |hook|
      hook.call(job)
    end
  end

  def perform
    promise.set_start

    begin
      Mcfly.whodunnit = promise.user

      mod = module_name.constantize
      res = { 'result' => mod.send(method_name, *method_args) }
    rescue StandardError => e
      res = ::Marty::Promise.exception_to_result(promise: promise, exception: e)
    end

    promise.set_result(res)
    process_hook(res)
  end

  def process_hook(res)
    return unless hook

    hook.run(params: method_args, result: res)
  rescue StandardError => e
    Marty::Util.logger.error "promise hook failed: #{e}"
  end

  def max_attempts
    1
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
marty-6.1.0 lib/marty/promise_ruby_job.rb
marty-5.2.0 lib/marty/promise_ruby_job.rb
marty-5.1.4 lib/marty/promise_ruby_job.rb
marty-5.1.3 lib/marty/promise_ruby_job.rb
marty-5.1.2 lib/marty/promise_ruby_job.rb
marty-5.1.1 lib/marty/promise_ruby_job.rb
marty-5.1.0 lib/marty/promise_ruby_job.rb
marty-3.1.0 lib/marty/promise_ruby_job.rb