Class: Taskinator::Task::Job
- Inherits:
-
Taskinator::Task
- Object
- Taskinator::Task
- Taskinator::Task::Job
- 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
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
Attributes inherited from Taskinator::Task
#created_at, #definition, #next, #options, #process, #queue, #updated_at, #uuid
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #enqueue ⇒ Object
-
#initialize(process, job, args, options = {}) ⇒ Job
constructor
A new instance of Job.
- #inspect ⇒ Object
- #start ⇒ Object
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.
215 216 217 218 219 220 221 222 223 |
# File 'lib/taskinator/task.rb', line 215 def initialize(process, job, args, ={}) super(process, ) 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
#args ⇒ Object (readonly)
Returns the value of attribute args.
213 214 215 |
# File 'lib/taskinator/task.rb', line 213 def args @args end |
#job ⇒ Object (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 |
#enqueue ⇒ Object
225 226 227 |
# File 'lib/taskinator/task.rb', line 225 def enqueue Taskinator.queue.enqueue_task(self) end |
#inspect ⇒ Object
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 |
#start ⇒ Object
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 |