Class: LevelUp::Task

Inherits:
Object
  • Object
show all
Defined in:
app/models/level_up/task.rb

Direct Known Subclasses

Cancel, End, Start

Defined Under Namespace

Classes: Cancel, End, Start

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, allow_transition, allow_retry) ⇒ Task

Returns a new instance of Task.



6
7
8
9
10
# File 'app/models/level_up/task.rb', line 6

def initialize(job, allow_transition, allow_retry)
  self.job = job
  self.allow_transition = allow_transition
  self.allow_retry = allow_retry
end

Instance Attribute Details

#allow_retryObject

Returns the value of attribute allow_retry.



4
5
6
# File 'app/models/level_up/task.rb', line 4

def allow_retry
  @allow_retry
end

#allow_transitionObject

Returns the value of attribute allow_transition.



4
5
6
# File 'app/models/level_up/task.rb', line 4

def allow_transition
  @allow_transition
end

#jobObject

Returns the value of attribute job.



4
5
6
# File 'app/models/level_up/task.rb', line 4

def job
  @job
end

Instance Method Details

#execute(receiver, method_name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/level_up/task.rb', line 12

def execute(receiver, method_name)
  task_name = retry_params = task_description = nil
  ActiveRecord::Base.transaction do
    task_name = catch(:move_to) do
      retry_params = catch(:retry_in) do
        task_description = catch(:manual_task) do
          receiver.send(method_name)
          nil
        end
        nil
      end
      nil
    end
  end

  if self.allow_transition
    self.job.next_task = task_name
  end

  if retry_params and self.allow_retry
    self.job.retry_at = retry_params[:delay].from_now
  end

  if task_description
    self.job.manual_task = true
    self.job.manual_task_description = task_description
  end
end

#manual_task!(description) ⇒ Object



49
50
51
# File 'app/models/level_up/task.rb', line 49

def manual_task!(description)
  self.job.manual_task!(description)
end

#move_to!(task_name) ⇒ Object



41
42
43
# File 'app/models/level_up/task.rb', line 41

def move_to!(task_name)
  self.job.move_to!(task_name)
end

#retry_in!(delay, error = nil) ⇒ Object



45
46
47
# File 'app/models/level_up/task.rb', line 45

def retry_in!(delay, error=nil)
  self.job.retry_in!(delay, error)
end