Class: Marty::PromiseRubyJob

Inherits:
Struct
  • Object
show all
Defined in:
lib/marty/promise_ruby_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hookObject

Returns the value of attribute hook



1
2
3
# File 'lib/marty/promise_ruby_job.rb', line 1

def hook
  @hook
end

#method_argsObject

Returns the value of attribute method_args



1
2
3
# File 'lib/marty/promise_ruby_job.rb', line 1

def method_args
  @method_args
end

#method_nameObject

Returns the value of attribute method_name



1
2
3
# File 'lib/marty/promise_ruby_job.rb', line 1

def method_name
  @method_name
end

#module_nameObject

Returns the value of attribute module_name



1
2
3
# File 'lib/marty/promise_ruby_job.rb', line 1

def module_name
  @module_name
end

#promiseObject

Returns the value of attribute promise



1
2
3
# File 'lib/marty/promise_ruby_job.rb', line 1

def promise
  @promise
end

#titleObject

Returns the value of attribute title



1
2
3
# File 'lib/marty/promise_ruby_job.rb', line 1

def title
  @title
end

Instance Method Details

#enqueue(job) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/marty/promise_ruby_job.rb', line 9

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

#max_attemptsObject



44
45
46
# File 'lib/marty/promise_ruby_job.rb', line 44

def max_attempts
  1
end

#performObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/marty/promise_ruby_job.rb', line 20

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

#process_hook(res) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/marty/promise_ruby_job.rb', line 36

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