Class: Taskinator::Task::Job

Inherits:
Taskinator::Task show all
Defined in:
lib/taskinator/task.rb

Overview

a task which invokes the specified background job the args must be intrinsic types, since they are serialized to YAML

Instance Attribute Summary collapse

Attributes inherited from Taskinator::Task

#next, #options, #process, #uuid

Instance Method Summary collapse

Methods inherited from Taskinator::Task

#<=>, base_key, #cancelled?, define_job_task, define_step_task, define_sub_process_task, #on_completed_entry, #on_failed_entry, #paused?, #queue, #to_s

Methods included from Persistence

add_process_to_list, included, list_key

Constructor Details

#initialize(process, job, args, options = {}) ⇒ Job

Returns a new instance of Job.

Raises:

  • (ArgumentError)


177
178
179
180
181
182
183
184
185
186
# File 'lib/taskinator/task.rb', line 177

def initialize(process, job, args, options={})
  super(process, options)
  @definition = process.definition  # for convenience

  raise ArgumentError, 'job' if job.nil?
  raise ArgumentError, 'job' unless job.methods.include?(:perform) || job.instance_methods.include?(:perform)

  @job = job
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



175
176
177
# File 'lib/taskinator/task.rb', line 175

def args
  @args
end

#definitionObject (readonly)

Returns the value of attribute definition.



173
174
175
# File 'lib/taskinator/task.rb', line 173

def definition
  @definition
end

#jobObject (readonly)

Returns the value of attribute job.



174
175
176
# File 'lib/taskinator/task.rb', line 174

def job
  @job
end

Instance Method Details

#accept(visitor) ⇒ Object



202
203
204
205
206
207
# File 'lib/taskinator/task.rb', line 202

def accept(visitor)
  super
  visitor.visit_type(:definition)
  visitor.visit_type(:job)
  visitor.visit_args(:args)
end

#can_complete_task?Boolean

NOTE: this _does not_ work when checking out-of-process

Returns:

  • (Boolean)


198
199
200
# File 'lib/taskinator/task.rb', line 198

def can_complete_task?
  defined?(@is_complete) && @is_complete
end

#enqueueObject



188
189
190
# File 'lib/taskinator/task.rb', line 188

def enqueue
  Taskinator.queue.enqueue_job(self)
end

#perform {|job, args| ... } ⇒ Object

Yields:



192
193
194
195
# File 'lib/taskinator/task.rb', line 192

def perform(&block)
  yield(job, args)
  @is_complete = true
end