Class: Taskinator::Process

Inherits:
Object
  • Object
show all
Includes:
Comparable, Persistence, Workflow
Defined in:
lib/taskinator/process.rb

Direct Known Subclasses

Concurrent, Sequential

Defined Under Namespace

Classes: Concurrent, Sequential

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
# File 'lib/taskinator/process.rb', line 28

def initialize(definition, options={})
  raise ArgumentError, 'definition' if definition.nil?
  raise ArgumentError, "#{definition.name} does not extend the #{Definition.name} module" unless definition.kind_of?(Definition)

  @uuid = options.delete(:uuid) || SecureRandom.uuid
  @definition = definition
  @options = options
  @queue = options.delete(:queue)
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



21
22
23
# File 'lib/taskinator/process.rb', line 21

def definition
  @definition
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/taskinator/process.rb', line 22

def options
  @options
end

#parentObject

in the case of sub process tasks, the containing task



26
27
28
# File 'lib/taskinator/process.rb', line 26

def parent
  @parent
end

#queueObject (readonly)

Returns the value of attribute queue.



23
24
25
# File 'lib/taskinator/process.rb', line 23

def queue
  @queue
end

#uuidObject (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_keyObject



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, options={})
  Process::Concurrent.new(definition, complete_on, options)
end

.define_sequential_process_for(definition, options = {}) ⇒ Object



7
8
9
# File 'lib/taskinator/process.rb', line 7

def define_sequential_process_for(definition, options={})
  Process::Sequential.new(definition, options)
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

#enqueueObject



124
125
126
# File 'lib/taskinator/process.rb', line 124

def enqueue
  Taskinator.queue.enqueue_process(self)
end

#no_tasks_defined?Boolean

Returns:

  • (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

#reloadObject

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

#tasksObject



38
39
40
# File 'lib/taskinator/process.rb', line 38

def tasks
  @tasks ||= Tasks.new
end

#tasks_completed?(*args) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


109
110
111
112
# File 'lib/taskinator/process.rb', line 109

def tasks_completed?(*args)
  # subclasses must implement this method
  raise NotImplementedError
end

#to_sObject



55
56
57
# File 'lib/taskinator/process.rb', line 55

def to_s
  "#<#{self.class.name}:#{uuid}>"
end