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.
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
Attributes inherited from Taskinator::Task
#created_at, #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.
214 215 216 217 218 219 220 221 222 223 |
# File 'lib/taskinator/task.rb', line 214 def initialize(process, job, args, ={}) super(process, ) @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
#args ⇒ Object (readonly)
Returns the value of attribute args.
212 213 214 |
# File 'lib/taskinator/task.rb', line 212 def args @args end |
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
210 211 212 |
# File 'lib/taskinator/task.rb', line 210 def definition @definition end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
211 212 213 |
# File 'lib/taskinator/task.rb', line 211 def job @job end |
Instance Method Details
#accept(visitor) ⇒ Object
251 252 253 254 255 256 |
# File 'lib/taskinator/task.rb', line 251 def accept(visitor) super visitor.visit_type(:definition) 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
258 259 260 |
# File 'lib/taskinator/task.rb', line 258 def inspect %(#<#{self.class.name}:0x#{self.__id__.to_s(16)} uuid="#{uuid}", 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 249 |
# 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! # FIXME: possible implement using ActiveJob instead, so it doesn't matter how the worker is implemented if job.instance_of?(Module) # 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 |