Class: LevelUp::Task
- Inherits:
-
Object
- Object
- LevelUp::Task
- Defined in:
- app/models/level_up/task.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#allow_retry ⇒ Object
Returns the value of attribute allow_retry.
-
#allow_transition ⇒ Object
Returns the value of attribute allow_transition.
-
#job ⇒ Object
Returns the value of attribute job.
Instance Method Summary collapse
- #execute(receiver, method_name) ⇒ Object
-
#initialize(job, allow_transition, allow_retry) ⇒ Task
constructor
A new instance of Task.
- #manual_task!(description) ⇒ Object
- #move_to!(task_name) ⇒ Object
- #retry_in!(delay, error = nil) ⇒ Object
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_retry ⇒ Object
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_transition ⇒ Object
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 |
#job ⇒ Object
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 |