Class: Taskinator::Task

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

Defined Under Namespace

Classes: Step, SubProcess

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Persistence

included

Constructor Details

#initialize(name, process, options = {}) ⇒ Task

Returns a new instance of Task.

Raises:

  • (ArgumentError)


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

def initialize(name, process, options={})
  raise ArgumentError, 'process' if process.nil? || !process.is_a?(Process)

  @uuid = SecureRandom.uuid
  @process = process
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#nextObject

the next task in the sequence



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

def next
  @next
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#processObject (readonly)

Returns the value of attribute process.



20
21
22
# File 'lib/taskinator/task.rb', line 20

def process
  @process
end

#uuidObject (readonly)

Returns the value of attribute uuid.



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

def uuid
  @uuid
end

Class Method Details

.base_keyObject



15
16
17
# File 'lib/taskinator/task.rb', line 15

def base_key
  'task'
end

.define_step_task(name, process, method, args, options = {}) ⇒ Object



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

def define_step_task(name, process, method, args, options={})
  Step.new(name, process, method, args, options)
end

.define_sub_process_task(name, process, sub_process, options = {}) ⇒ Object



11
12
13
# File 'lib/taskinator/task.rb', line 11

def define_sub_process_task(name, process, sub_process, options={})
  SubProcess.new(name, process, sub_process, options)
end

Instance Method Details

#<=>(other) ⇒ Object



45
46
47
# File 'lib/taskinator/task.rb', line 45

def <=>(other)
  uuid <=> other.uuid
end

#accept(visitor) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/taskinator/task.rb', line 37

def accept(visitor)
  visitor.visit_attribute(:uuid)
  visitor.visit_process_reference(:process)
  visitor.visit_attribute(:name)
  visitor.visit_task_reference(:next)
  visitor.visit_args(:options)
end

#can_complete_task?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


81
82
83
84
# File 'lib/taskinator/task.rb', line 81

def can_complete_task?
  # subclasses must implement this method
  raise NotImplementedError
end

#cancelled?Boolean

helper method, delegating to process

Returns:

  • (Boolean)


107
108
109
# File 'lib/taskinator/task.rb', line 107

def cancelled?
  process.cancelled?
end

#enqueueObject



91
92
93
# File 'lib/taskinator/task.rb', line 91

def enqueue
  Taskinator.queue.enqueue_task(self)
end

#on_completed_entry(*args) ⇒ Object

callback for when the task has completed



96
97
98
99
# File 'lib/taskinator/task.rb', line 96

def on_completed_entry(*args)
  # notify the process that this task has completed
  process.task_completed(self)
end

#paused?Boolean

helper method, delegating to process

Returns:

  • (Boolean)


102
103
104
# File 'lib/taskinator/task.rb', line 102

def paused?
  process.paused?
end

#to_sObject



49
50
51
# File 'lib/taskinator/task.rb', line 49

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