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

#created_at, #definition, #next, #options, #process, #queue, #updated_at, #uuid

Instance Method Summary collapse

Methods inherited from Taskinator::Task

#<=>, #cancel!, #cancelled?, #complete!, define_job_task, define_step_task, define_sub_process_task, #enqueue!, #fail!, #incr_count?, #paused?, #start!, #to_s

Methods included from Instrumentation

#cancelled_payload, #completed_payload, #enqueued_payload, #failed_payload, #instrument, #paused_payload, #processing_payload, #resumed_payload

Methods included from Persistence

add_process_to_list, deserialize, included, processes_list_key, serialize

Methods included from Workflow

#current_state, #current_state=, #transition

Constructor Details

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

Returns a new instance of Job.

Raises:

  • (ArgumentError)


215
216
217
218
219
220
221
222
223
# File 'lib/taskinator/task.rb', line 215

def initialize(process, job, args, options={})
  super(process, options)

  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.



213
214
215
# File 'lib/taskinator/task.rb', line 213

def args
  @args
end

#jobObject (readonly)

Returns the value of attribute job.



212
213
214
# File 'lib/taskinator/task.rb', line 212

def job
  @job
end

Instance Method Details

#accept(visitor) ⇒ Object



250
251
252
253
254
# File 'lib/taskinator/task.rb', line 250

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

#enqueueObject



225
226
227
# File 'lib/taskinator/task.rb', line 225

def enqueue
  Taskinator.queue.enqueue_task(self)
end

#inspectObject



256
257
258
# File 'lib/taskinator/task.rb', line 256

def inspect
  %(#<#{self.class.name}:0x#{self.__id__.to_s(16)} uuid="#{uuid}", definition=:#{definition}, job=#{job}, args=#{args}, current_state=:#{current_state}>)
end

#startObject



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/taskinator/task.rb', line 229

def start
  # NNB: if other job types are required, may need to implement how they get invoked here!

  if job.respond_to?(:perform)
    # resque
    job.perform(*args)
  else
    # delayedjob and sidekiq
    job.new.perform(*args)
  end

  # ASSUMPTION: when the job returns, the task is considered to be complete
  complete!

rescue => e
  Taskinator.logger.error(e)
  Taskinator.logger.debug(e.backtrace)
  fail!(e)
  raise e
end