class Rekiq::Contract

Attributes

addon[RW]
cancel_args[RW]
schedule[RW]
schedule_expired[RW]
schedule_post_work[RW]
work_time_shift[RW]
work_time_tolerance[RW]

Public Class Methods

from_hash(hash) click to toggle source
# File lib/rekiq/contract.rb, line 19
def from_hash(hash)
  new 'schedule'            => Marshal.load(hash['s'].encode('ISO-8859-1')),
      'cancel_args'         => hash['ca'],
      'addon'               => hash['ao'],
      'schedule_post_work'  => hash['pw'],
      'work_time_shift'     => hash['ws'],
      'work_time_tolerance' => hash['wt'],
      'schedule_expired'    => hash['se']
end
new(attributes = {}) click to toggle source
# File lib/rekiq/contract.rb, line 30
def initialize(attributes = {})
  @schedule            = attributes['schedule']
  @cancel_args         = attributes['cancel_args']
  @addon               = attributes['addon']
  @schedule_post_work  = attributes['schedule_post_work']
  @work_time_shift     = attributes['work_time_shift']
  @work_time_tolerance = attributes['work_time_tolerance']
  @schedule_expired    = attributes['schedule_expired']
end

Public Instance Methods

initial_work_time(from) click to toggle source
# File lib/rekiq/contract.rb, line 52
def initial_work_time(from)
  from = (shift > 0 ? from - shift : from) - tolerance
  calculate_work_time(from)
end
next_work_time(previous_work_time) click to toggle source
# File lib/rekiq/contract.rb, line 57
def next_work_time(previous_work_time)
  from = previous_work_time - shift
  calculate_work_time(from)
end
schedule_post_work?() click to toggle source
# File lib/rekiq/contract.rb, line 62
def schedule_post_work?
  unless schedule_post_work.nil?
    schedule_post_work
  else
    Rekiq.configuration.schedule_post_work
  end
end
to_hash() click to toggle source
# File lib/rekiq/contract.rb, line 40
def to_hash
  {
    's'  => Marshal.dump(schedule).force_encoding('ISO-8859-1').encode('UTF-8'),
    'ca' => cancel_args,
    'ao' => addon,
    'pw' => schedule_post_work,
    'ws' => work_time_shift,
    'wt' => work_time_tolerance,
    'se' => schedule_expired
  }.delete_if { |k, v| v.nil? }
end

Protected Instance Methods

calculate_work_time(from) click to toggle source
# File lib/rekiq/contract.rb, line 72
def calculate_work_time(from)
  if schedule_expired?
    from      = schedule.next_occurrence(from)
    work_time = from.nil? ? nil : from + shift
  else
    begin
      from      = schedule.next_occurrence(from)
      work_time = from.nil? ? nil : from + shift
    end until work_time.nil? || work_time > expiration_time
  end

  work_time
end
expiration_time() click to toggle source
# File lib/rekiq/contract.rb, line 86
def expiration_time
  Time.now - tolerance
end
schedule_expired?() click to toggle source
# File lib/rekiq/contract.rb, line 106
def schedule_expired?
  unless schedule_expired.nil?
    schedule_expired
  else
    Rekiq.configuration.schedule_expired
  end
end
shift() click to toggle source
# File lib/rekiq/contract.rb, line 90
def shift
  unless work_time_shift.nil?
    work_time_shift
  else
    Rekiq.configuration.work_time_shift
  end
end
tolerance() click to toggle source
# File lib/rekiq/contract.rb, line 98
def tolerance
  unless work_time_tolerance.nil?
    work_time_tolerance
  else
    Rekiq.configuration.work_time_tolerance
  end
end