Class: Taskinator::Task

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

Direct Known Subclasses

Job, Step, SubProcess

Defined Under Namespace

Classes: Job, Step, SubProcess

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Persistence

add_process_to_list, included, list_key

Constructor Details

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

Returns a new instance of Task.

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
# File 'lib/taskinator/task.rb', line 31

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



29
30
31
# File 'lib/taskinator/task.rb', line 29

def next
  @next
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#processObject (readonly)

Returns the value of attribute process.



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

def process
  @process
end

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



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, options={})
  Job.new(process, job, args, options)
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



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

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

Instance Method Details

#<=>(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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)


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

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

#cancelled?Boolean

helper method, delegating to process

Returns:

  • (Boolean)


125
126
127
# File 'lib/taskinator/task.rb', line 125

def cancelled?
  process.cancelled?
end

#enqueueObject



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

def enqueue
  Taskinator.queue.enqueue_task(self)
end

#on_completed_entry(*args) ⇒ Object

callback for when the task has completed



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

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



114
115
116
117
# File 'lib/taskinator/task.rb', line 114

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

Returns:

  • (Boolean)


120
121
122
# File 'lib/taskinator/task.rb', line 120

def paused?
  process.paused?
end

#queueObject



54
55
56
# File 'lib/taskinator/task.rb', line 54

def queue
  options[:queue]
end

#to_sObject



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

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