Class: Taskinator::Process
- Inherits:
-
Object
- Object
- Taskinator::Process
- Includes:
- Comparable, Persistence, Workflow
- Defined in:
- lib/taskinator/process.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Concurrent, Sequential
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
in the case of sub process tasks, the containing task.
-
#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_concurrent_process_for(definition, complete_on = CompleteOn::Default, options = {}) ⇒ Object
- .define_sequential_process_for(definition, options = {}) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #enqueue ⇒ Object
-
#initialize(definition, options = {}) ⇒ Process
constructor
A new instance of Process.
- #no_tasks_defined? ⇒ Boolean
-
#on_completed_entry(*args) ⇒ Object
callback for when the process has completed.
-
#on_failed_entry(*args) ⇒ Object
callback for when the process has failed.
-
#reload ⇒ Object
reloads the process from storage NB: only implemented by LazyLoader so that the process can be lazy loaded, thereafter it has no effect.
- #task_failed(task, error) ⇒ Object
- #tasks ⇒ Object
- #tasks_completed?(*args) ⇒ Boolean
- #to_s ⇒ Object
Methods included from Persistence
add_process_to_list, deserialize, included, list_key, serialize
Constructor Details
#initialize(definition, options = {}) ⇒ Process
Returns a new instance of Process.
28 29 30 31 32 33 34 35 36 |
# File 'lib/taskinator/process.rb', line 28 def initialize(definition, ={}) raise ArgumentError, 'definition' if definition.nil? raise ArgumentError, "#{definition.name} does not extend the #{Definition.name} module" unless definition.kind_of?(Definition) @uuid = .delete(:uuid) || SecureRandom.uuid @definition = definition = @queue = .delete(:queue) end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
21 22 23 |
# File 'lib/taskinator/process.rb', line 21 def definition @definition end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/taskinator/process.rb', line 22 def end |
#parent ⇒ Object
in the case of sub process tasks, the containing task
26 27 28 |
# File 'lib/taskinator/process.rb', line 26 def parent @parent end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
23 24 25 |
# File 'lib/taskinator/process.rb', line 23 def queue @queue end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
20 21 22 |
# File 'lib/taskinator/process.rb', line 20 def uuid @uuid end |
Class Method Details
.base_key ⇒ Object
15 16 17 |
# File 'lib/taskinator/process.rb', line 15 def base_key 'process' end |
.define_concurrent_process_for(definition, complete_on = CompleteOn::Default, options = {}) ⇒ Object
11 12 13 |
# File 'lib/taskinator/process.rb', line 11 def define_concurrent_process_for(definition, complete_on=CompleteOn::Default, ={}) Process::Concurrent.new(definition, complete_on, ) end |
.define_sequential_process_for(definition, options = {}) ⇒ Object
7 8 9 |
# File 'lib/taskinator/process.rb', line 7 def define_sequential_process_for(definition, ={}) Process::Sequential.new(definition, ) end |
Instance Method Details
#<=>(other) ⇒ Object
51 52 53 |
# File 'lib/taskinator/process.rb', line 51 def <=>(other) uuid <=> other.uuid end |
#accept(visitor) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/taskinator/process.rb', line 42 def accept(visitor) visitor.visit_attribute(:uuid) visitor.visit_task_reference(:parent) visitor.visit_type(:definition) visitor.visit_tasks(tasks) visitor.visit_args(:options) visitor.visit_attribute(:queue) end |
#enqueue ⇒ Object
124 125 126 |
# File 'lib/taskinator/process.rb', line 124 def enqueue Taskinator.queue.enqueue_process(self) end |
#no_tasks_defined? ⇒ Boolean
105 106 107 |
# File 'lib/taskinator/process.rb', line 105 def no_tasks_defined? tasks.empty? end |
#on_completed_entry(*args) ⇒ Object
callback for when the process has completed
129 130 131 132 133 |
# File 'lib/taskinator/process.rb', line 129 def on_completed_entry(*args) # notify the parent task (if there is one) that this process has completed # note: parent may be a proxy, so explicity check for nil? parent.complete! unless parent.nil? end |
#on_failed_entry(*args) ⇒ Object
callback for when the process has failed
136 137 138 139 140 |
# File 'lib/taskinator/process.rb', line 136 def on_failed_entry(*args) # notify the parent task (if there is one) that this process has failed # note: parent may be a proxy, so explicity check for nil? parent.fail!(*args) unless parent.nil? end |
#reload ⇒ Object
reloads the process from storage NB: only implemented by LazyLoader so that
the process can be lazy loaded, thereafter
it has no effect
208 209 210 |
# File 'lib/taskinator/process.rb', line 208 def reload false end |
#task_failed(task, error) ⇒ Object
114 115 116 117 |
# File 'lib/taskinator/process.rb', line 114 def task_failed(task, error) # for now, fail this process fail!(error) end |
#tasks ⇒ Object
38 39 40 |
# File 'lib/taskinator/process.rb', line 38 def tasks @tasks ||= Tasks.new end |
#tasks_completed?(*args) ⇒ Boolean
109 110 111 112 |
# File 'lib/taskinator/process.rb', line 109 def tasks_completed?(*args) # subclasses must implement this method raise NotImplementedError end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/taskinator/process.rb', line 55 def to_s "#<#{self.class.name}:#{uuid}>" end |