Class: Edamame::Job

Inherits:
Struct
  • Object
show all
Includes:
JobCore
Defined in:
lib/edamame/job.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  'priority'   => 65536,
  'ttr'        => 120,
  'state'      => 1,
  'scheduling' => Edamame::Scheduling::Once.new()
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JobCore

#key, #since_last

Constructor Details

#initialize(*args) ⇒ Job

attr_accessor :runs, :failures, :prev_run_at



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/edamame/job.rb', line 103

def initialize *args
  super *args
  DEFAULT_OPTIONS.each{|key,val| self[key] ||= val }
  [:priority, :ttr, :state].each{|key| self[key] = self[key].to_i }
  case self.scheduling
  when String
    scheduling_hash = YAML.load(self.scheduling) rescue nil
    self.scheduling = Scheduling.from_hash(scheduling_hash) if scheduling_hash
  when Hash
    self.scheduling = Scheduling.from_hash(scheduling)
  else raise "Can't build a Scheduling from #{self.scheduling}" ;  end
  if self.obj.is_a?(String)        then self.obj        = YAML.load(self.obj)        rescue nil ; end
end

Instance Attribute Details

#objObject

Returns the value of attribute obj

Returns:

  • (Object)

    the current value of obj



88
89
90
# File 'lib/edamame/job.rb', line 88

def obj
  @obj
end

#priorityObject

Returns the value of attribute priority

Returns:

  • (Object)

    the current value of priority



88
89
90
# File 'lib/edamame/job.rb', line 88

def priority
  @priority
end

#schedulingObject

Returns the value of attribute scheduling

Returns:

  • (Object)

    the current value of scheduling



88
89
90
# File 'lib/edamame/job.rb', line 88

def scheduling
  @scheduling
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



88
89
90
# File 'lib/edamame/job.rb', line 88

def state
  @state
end

#ttrObject

Returns the value of attribute ttr

Returns:

  • (Object)

    the current value of ttr



88
89
90
# File 'lib/edamame/job.rb', line 88

def ttr
  @ttr
end

#tubeObject

Returns the value of attribute tube

Returns:

  • (Object)

    the current value of tube



88
89
90
# File 'lib/edamame/job.rb', line 88

def tube
  @tube
end

Instance Method Details

#delayObject



117
118
119
# File 'lib/edamame/job.rb', line 117

def delay
  scheduling.delay
end

#to_hash(flatten = true) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/edamame/job.rb', line 121

def to_hash flatten=true
  hsh = super()
  hsh["scheduling"] = scheduling.to_hash
  hsh["obj"]        = obj.to_hash
  if flatten
    hsh["scheduling"] = hsh['scheduling'].to_yaml
    hsh["obj"]        = hsh['obj'].to_yaml
  end
  hsh
end