Class: Taskinator::Task

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

Direct Known Subclasses

Step, SubProcess

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(process, options = {}) ⇒ Task

Returns a new instance of Task.

Raises:

  • (ArgumentError)


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

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

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

Instance Attribute Details

#nextObject

the next task in the sequence



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

def next
  @next
end

#optionsObject (readonly)

Returns the value of attribute options.



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

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(process, method, args, options = {}) ⇒ Object



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

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

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



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

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

Instance Method Details

#<=>(other) ⇒ Object



42
43
44
# File 'lib/taskinator/task.rb', line 42

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

#accept(visitor) ⇒ Object



35
36
37
38
39
40
# File 'lib/taskinator/task.rb', line 35

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

#can_complete_task?(*args) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


78
79
80
81
# File 'lib/taskinator/task.rb', line 78

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

#cancelled?Boolean

helper method, delegating to process

Returns:

  • (Boolean)


104
105
106
# File 'lib/taskinator/task.rb', line 104

def cancelled?
  process.cancelled?
end

#enqueueObject



88
89
90
# File 'lib/taskinator/task.rb', line 88

def enqueue
  Taskinator.queue.enqueue_task(self)
end

#on_completed_entry(*args) ⇒ Object

callback for when the task has completed



93
94
95
96
# File 'lib/taskinator/task.rb', line 93

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)


99
100
101
# File 'lib/taskinator/task.rb', line 99

def paused?
  process.paused?
end

#to_sObject



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

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