Class: RCelery::Task::Runner

Inherits:
Object
  • Object
show all
Includes:
States
Defined in:
lib/rcelery/task/runner.rb

Constant Summary

Constants included from States

States::FAILURE, States::RETRY, States::SUCCESS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ Runner

Returns a new instance of Runner.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rcelery/task/runner.rb', line 14

def initialize(message)
  @task = Task.all_tasks[message['task']]
  @task_id = message['id']
  @eager = message['eager'].nil? ? false : message['eager']

  @args = [message['args'], message['kwargs']].flatten.compact
  @args.pop if @args.last.is_a?(Hash) && @args.last.empty?

  @queue = Task.result_queue(@task_id) unless eager_mode?
  @task.request.update(
    :task_id => @task_id,
    :retries => message['retries'] || 0,
    :args => message['args'],
    :kwargs => message['kwargs']
  )
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



12
13
14
# File 'lib/rcelery/task/runner.rb', line 12

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



12
13
14
# File 'lib/rcelery/task/runner.rb', line 12

def status
  @status
end

#taskObject (readonly)

Returns the value of attribute task.



12
13
14
# File 'lib/rcelery/task/runner.rb', line 12

def task
  @task
end

Instance Method Details

#executeObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rcelery/task/runner.rb', line 31

def execute
  result = @task.method.call(*@args)
  @status = SUCCESS
  @result = result
  publish_result if publish_result?
rescue RetryError => raised
  @result = raised
  @status = RETRY
rescue Exception => raised
  @result = raised
  @status = FAILURE
  publish_result if publish_result?
ensure
  @task.request.clear
end