Class: Beanstalk::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/beanstalk-client/job.rb

Constant Summary collapse

DELAY_MAX =

Don’t delay for more than 48 hours at a time.

60 * 60 * 48

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conn, id, pri, body) ⇒ Job

Returns a new instance of Job.



39
40
41
42
43
44
45
# File 'lib/beanstalk-client/job.rb', line 39

def initialize(conn, id, pri, body)
  @conn = conn
  @id = id
  @pri = pri
  @body = body
  @deleted = false
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



21
22
23
# File 'lib/beanstalk-client/job.rb', line 21

def body
  @body
end

#connObject (readonly)

Returns the value of attribute conn.



21
22
23
# File 'lib/beanstalk-client/job.rb', line 21

def conn
  @conn
end

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/beanstalk-client/job.rb', line 21

def id
  @id
end

#priObject (readonly)

Returns the value of attribute pri.



21
22
23
# File 'lib/beanstalk-client/job.rb', line 21

def pri
  @pri
end

Instance Method Details

#[](name) ⇒ Object

Convenience method for getting ybody elements.



24
25
26
# File 'lib/beanstalk-client/job.rb', line 24

def [](name)
  ybody[name]
end

#[]=(name, val) ⇒ Object

Convenience method for setting ybody elements.



29
30
31
# File 'lib/beanstalk-client/job.rb', line 29

def []=(name, val)
  ybody[name] = val
end

#ageObject



70
# File 'lib/beanstalk-client/job.rb', line 70

def age() stats['age'] end

#bury(newpri = pri) ⇒ Object



60
61
62
# File 'lib/beanstalk-client/job.rb', line 60

def bury(newpri=pri)
  @conn.bury(id, newpri)
end

#decay(d = ([1, delay].max * 1.3).ceil) ⇒ Object



81
82
83
84
# File 'lib/beanstalk-client/job.rb', line 81

def decay(d=([1, delay].max * 1.3).ceil)
  return bury() if delay >= DELAY_MAX
  release(pri, d)
end

#delayObject



72
# File 'lib/beanstalk-client/job.rb', line 72

def delay() stats.fetch('delay', 0) end

#deleteObject



47
48
49
50
# File 'lib/beanstalk-client/job.rb', line 47

def delete()
  @conn.delete(id) if !@deleted
  @deleted = true
end

#inspectObject



90
91
92
# File 'lib/beanstalk-client/job.rb', line 90

def inspect
  "(job server=#{server} id=#{id} pri=#{pri} size=#{body.size})"
end

#put_back(pri = self.pri) ⇒ Object



52
53
54
# File 'lib/beanstalk-client/job.rb', line 52

def put_back(pri=self.pri)
  @conn.put(body, pri)
end

#release(newpri = pri, delay = 0) ⇒ Object



56
57
58
# File 'lib/beanstalk-client/job.rb', line 56

def release(newpri=pri, delay=0)
  @conn.release(id, newpri, delay)
end

#serverObject



74
75
76
# File 'lib/beanstalk-client/job.rb', line 74

def server()
  @conn.addr
end

#stateObject



71
# File 'lib/beanstalk-client/job.rb', line 71

def state() stats['state'] end

#statsObject



64
65
66
# File 'lib/beanstalk-client/job.rb', line 64

def stats()
  @conn.job_stats(id)
end

#time_leftObject



69
# File 'lib/beanstalk-client/job.rb', line 69

def time_left() stats['time-left'] end

#timeoutsObject



68
# File 'lib/beanstalk-client/job.rb', line 68

def timeouts() stats['timeouts'] end

#to_sObject



86
87
88
# File 'lib/beanstalk-client/job.rb', line 86

def to_s
  "(job #{body.inspect})"
end

#ybodyObject

Return the object that results from loading the body as a yaml stream. Return nil if the body is not a valid yaml stream.



35
36
37
# File 'lib/beanstalk-client/job.rb', line 35

def ybody()
  (@ybody ||= [begin YAML.load(body) rescue nil end])[0]
end