Class: BackgroundQueue::ServerLib::Config::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/background_queue/server_lib/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_entry) ⇒ Job

Returns a new instance of Job.



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/background_queue/server_lib/config.rb', line 281

def initialize(job_entry)
  raise "Empty Job Entry" if job_entry.nil?
  @at = BackgroundQueue::Utils.get_hash_entry(job_entry, :at)
  @in = BackgroundQueue::Utils.get_hash_entry(job_entry, :in)
  @cron = BackgroundQueue::Utils.get_hash_entry(job_entry, :cron)
  @every = BackgroundQueue::Utils.get_hash_entry(job_entry, :every)
  if !@at.nil?
    @type = :at
  elsif !@in.nil?
    @type = :in
  elsif !@cron.nil?
    @type=:cron
  elsif !@every.nil?
    @type=:every
  else
    raise "Job is missing timer designation (at, in or cron)"
  end
  @worker = BackgroundQueue::Utils.get_hash_entry(job_entry, :worker)
  raise "Job is missing worker entry" if @worker.nil?
  
  @args = {}
  args_entry = BackgroundQueue::Utils.get_hash_entry(job_entry, :args)
  unless args_entry.nil?
    raise "Invalid 'args' entry in job: expecting Hash of arguments, got #{args_entry.class.name}" unless args_entry.kind_of?(Hash)
    @args = args_entry
  end
  
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



279
280
281
# File 'lib/background_queue/server_lib/config.rb', line 279

def args
  @args
end

#atObject

Returns the value of attribute at.



274
275
276
# File 'lib/background_queue/server_lib/config.rb', line 274

def at
  @at
end

#cronObject

Returns the value of attribute cron.



276
277
278
# File 'lib/background_queue/server_lib/config.rb', line 276

def cron
  @cron
end

#everyObject

Returns the value of attribute every.



277
278
279
# File 'lib/background_queue/server_lib/config.rb', line 277

def every
  @every
end

#inObject

Returns the value of attribute in.



275
276
277
# File 'lib/background_queue/server_lib/config.rb', line 275

def in
  @in
end

#typeObject

Returns the value of attribute type.



278
279
280
# File 'lib/background_queue/server_lib/config.rb', line 278

def type
  @type
end

Instance Method Details

#run(server) ⇒ Object



331
332
333
334
# File 'lib/background_queue/server_lib/config.rb', line 331

def run(server)
  task = BackgroundQueue::ServerLib::Task.new(:system, :scheduled, self.object_id, 2, @worker, @args, server.config.system_task_options)
  server.task_queue.add_task(task)
end

#schedule(scheduler, server) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/background_queue/server_lib/config.rb', line 310

def schedule(scheduler, server)
  case @type
  when :at
    scheduler.at @at do
      run(server)
    end
  when :in
    scheduler.in @in do
      run(server)
    end
  when :cron
    scheduler.cron @cron do
      run(server)
    end
  when :every
    scheduler.every @every do
      run(server)
    end
  end
end