Class: Taskinator::Task
- Inherits:
-
Object
- Object
- Taskinator::Task
- Includes:
- Comparable, Persistence, Workflow
- Defined in:
- lib/taskinator/task.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Job, Step, SubProcess
Instance Attribute Summary collapse
-
#next ⇒ Object
the next task in the sequence.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#process ⇒ Object
readonly
Returns the value of attribute process.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
- .base_key ⇒ Object
- .define_job_task(process, job, args, options = {}) ⇒ Object
- .define_step_task(process, method, args, options = {}) ⇒ Object
- .define_sub_process_task(process, sub_process, options = {}) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #can_complete_task?(*args) ⇒ Boolean
-
#cancelled? ⇒ Boolean
helper method, delegating to process.
- #enqueue ⇒ Object
-
#initialize(process, options = {}) ⇒ Task
constructor
A new instance of Task.
-
#on_completed_entry(*args) ⇒ Object
callback for when the task has completed.
-
#on_failed_entry(*args) ⇒ Object
callback for when the task has failed.
-
#paused? ⇒ Boolean
helper method, delegating to process.
-
#reload ⇒ Object
reloads the task from storage NB: only implemented by LazyLoader so that the task can be lazy loaded, thereafter it has no effect.
- #to_s ⇒ Object
Methods included from Persistence
add_process_to_list, deserialize, included, list_key, serialize
Constructor Details
#initialize(process, options = {}) ⇒ Task
Returns a new instance of Task.
32 33 34 35 36 37 38 39 |
# File 'lib/taskinator/task.rb', line 32 def initialize(process, ={}) raise ArgumentError, 'process' if process.nil? || !process.is_a?(Process) @uuid = SecureRandom.uuid @process = process = @queue = .delete(:queue) end |
Instance Attribute Details
#next ⇒ Object
the next task in the sequence
30 31 32 |
# File 'lib/taskinator/task.rb', line 30 def next @next end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/taskinator/task.rb', line 26 def end |
#process ⇒ Object (readonly)
Returns the value of attribute process.
24 25 26 |
# File 'lib/taskinator/task.rb', line 24 def process @process end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
27 28 29 |
# File 'lib/taskinator/task.rb', line 27 def queue @queue end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
25 26 27 |
# File 'lib/taskinator/task.rb', line 25 def uuid @uuid end |
Class Method Details
.base_key ⇒ Object
19 20 21 |
# File 'lib/taskinator/task.rb', line 19 def base_key 'task' end |
.define_job_task(process, job, args, options = {}) ⇒ Object
11 12 13 |
# File 'lib/taskinator/task.rb', line 11 def define_job_task(process, job, args, ={}) Job.new(process, job, args, ) end |
.define_step_task(process, method, args, options = {}) ⇒ Object
7 8 9 |
# File 'lib/taskinator/task.rb', line 7 def define_step_task(process, method, args, ={}) Step.new(process, method, args, ) end |
.define_sub_process_task(process, sub_process, options = {}) ⇒ Object
15 16 17 |
# File 'lib/taskinator/task.rb', line 15 def define_sub_process_task(process, sub_process, ={}) SubProcess.new(process, sub_process, ) end |
Instance Method Details
#<=>(other) ⇒ Object
49 50 51 |
# File 'lib/taskinator/task.rb', line 49 def <=>(other) uuid <=> other.uuid end |
#accept(visitor) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/taskinator/task.rb', line 41 def accept(visitor) visitor.visit_attribute(:uuid) visitor.visit_process_reference(:process) visitor.visit_task_reference(:next) visitor.visit_args(:options) visitor.visit_attribute(:queue) end |
#can_complete_task?(*args) ⇒ Boolean
92 93 94 95 |
# File 'lib/taskinator/task.rb', line 92 def can_complete_task?(*args) # subclasses must implement this method raise NotImplementedError end |
#cancelled? ⇒ Boolean
helper method, delegating to process
124 125 126 |
# File 'lib/taskinator/task.rb', line 124 def cancelled? process.cancelled? end |
#enqueue ⇒ Object
102 103 104 |
# File 'lib/taskinator/task.rb', line 102 def enqueue Taskinator.queue.enqueue_task(self) end |
#on_completed_entry(*args) ⇒ Object
callback for when the task has completed
107 108 109 110 |
# File 'lib/taskinator/task.rb', line 107 def on_completed_entry(*args) # notify the process that this task has completed process.task_completed(self) end |
#on_failed_entry(*args) ⇒ Object
callback for when the task has failed
113 114 115 116 |
# File 'lib/taskinator/task.rb', line 113 def on_failed_entry(*args) # notify the process that this task has failed process.task_failed(self, args.last) end |
#paused? ⇒ Boolean
helper method, delegating to process
119 120 121 |
# File 'lib/taskinator/task.rb', line 119 def paused? process.paused? end |
#reload ⇒ Object
reloads the task from storage NB: only implemented by LazyLoader so that
the task can be lazy loaded, thereafter
it has no effect
246 247 248 |
# File 'lib/taskinator/task.rb', line 246 def reload false end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/taskinator/task.rb', line 53 def to_s "#<#{self.class.name}:#{uuid}>" end |