Class: BackgroundQueue::ServerLib::Config::Job
- Inherits:
-
Object
- Object
- BackgroundQueue::ServerLib::Config::Job
- Defined in:
- lib/background_queue/server_lib/config.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#at ⇒ Object
Returns the value of attribute at.
-
#cron ⇒ Object
Returns the value of attribute cron.
-
#every ⇒ Object
Returns the value of attribute every.
-
#in ⇒ Object
Returns the value of attribute in.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(job_entry) ⇒ Job
constructor
A new instance of Job.
- #run(server) ⇒ Object
- #schedule(scheduler, server) ⇒ Object
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
#args ⇒ Object
Returns the value of attribute args.
279 280 281 |
# File 'lib/background_queue/server_lib/config.rb', line 279 def args @args end |
#at ⇒ Object
Returns the value of attribute at.
274 275 276 |
# File 'lib/background_queue/server_lib/config.rb', line 274 def at @at end |
#cron ⇒ Object
Returns the value of attribute cron.
276 277 278 |
# File 'lib/background_queue/server_lib/config.rb', line 276 def cron @cron end |
#every ⇒ Object
Returns the value of attribute every.
277 278 279 |
# File 'lib/background_queue/server_lib/config.rb', line 277 def every @every end |
#in ⇒ Object
Returns the value of attribute in.
275 276 277 |
# File 'lib/background_queue/server_lib/config.rb', line 275 def in @in end |
#type ⇒ Object
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.) 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 |