Class: Reqless::RecurringJob

Inherits:
BaseJob
  • Object
show all
Defined in:
lib/reqless/job.rb

Overview

Wraps a recurring job

Instance Attribute Summary collapse

Attributes inherited from BaseJob

#client

Instance Method Summary collapse

Methods inherited from BaseJob

#==, #hash, #klass, #queue

Constructor Details

#initialize(client, atts) ⇒ RecurringJob

Returns a new instance of RecurringJob.



419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/reqless/job.rb', line 419

def initialize(client, atts)
  super(client, atts.fetch('jid'))
  %w{jid data priority tags retries interval count backlog}.each do |att|
    instance_variable_set("@#{att}".to_sym, atts.fetch(att))
  end

  # Parse the data string
  @data        = JSON.parse(@data)
  @klass_name  = atts.fetch('klass')
  @queue_name  = atts.fetch('queue')
  @tags        = [] if @tags == {}
end

Instance Attribute Details

#backlogObject

Returns the value of attribute backlog.



417
418
419
# File 'lib/reqless/job.rb', line 417

def backlog
  @backlog
end

#countObject (readonly)

Returns the value of attribute count.



416
417
418
# File 'lib/reqless/job.rb', line 416

def count
  @count
end

#dataObject

Returns the value of attribute data.



416
417
418
# File 'lib/reqless/job.rb', line 416

def data
  @data
end

#intervalObject

Returns the value of attribute interval.



416
417
418
# File 'lib/reqless/job.rb', line 416

def interval
  @interval
end

#jidObject (readonly)

Returns the value of attribute jid.



416
417
418
# File 'lib/reqless/job.rb', line 416

def jid
  @jid
end

#klass_nameObject (readonly)

Returns the value of attribute klass_name.



417
418
419
# File 'lib/reqless/job.rb', line 417

def klass_name
  @klass_name
end

#priorityObject

Returns the value of attribute priority.



416
417
418
# File 'lib/reqless/job.rb', line 416

def priority
  @priority
end

#queue_nameObject (readonly)

Returns the value of attribute queue_name.



417
418
419
# File 'lib/reqless/job.rb', line 417

def queue_name
  @queue_name
end

#retriesObject

Returns the value of attribute retries.



416
417
418
# File 'lib/reqless/job.rb', line 416

def retries
  @retries
end

#tagsObject (readonly)

Returns the value of attribute tags.



416
417
418
# File 'lib/reqless/job.rb', line 416

def tags
  @tags
end

Instance Method Details

#cancelObject



468
469
470
# File 'lib/reqless/job.rb', line 468

def cancel
  @client.call('recurringJob.cancel', @jid)
end

#klass=(value) ⇒ Object



452
453
454
455
# File 'lib/reqless/job.rb', line 452

def klass=(value)
  @client.call('recurringJob.update', @jid, 'klass', value.to_s)
  @klass_name = value.to_s
end

#last_spawned_jidObject



480
481
482
483
# File 'lib/reqless/job.rb', line 480

def last_spawned_jid
  return nil if never_spawned?
  "#{jid}-#{count}"
end

#last_spawned_jobObject



485
486
487
488
# File 'lib/reqless/job.rb', line 485

def last_spawned_job
  return nil if never_spawned?
  @client.jobs[last_spawned_jid]
end

#move(queue) ⇒ Object Also known as: requeue



462
463
464
465
# File 'lib/reqless/job.rb', line 462

def move(queue)
  @client.call('recurringJob.update', @jid, 'queue', queue)
  @queue_name = queue
end

#tag(*tags) ⇒ Object



472
473
474
# File 'lib/reqless/job.rb', line 472

def tag(*tags)
  @client.call('recurringJob.addTag', @jid, *tags)
end

#untag(*tags) ⇒ Object



476
477
478
# File 'lib/reqless/job.rb', line 476

def untag(*tags)
  @client.call('recurringJob.removeTag', @jid, *tags)
end