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, body) ⇒ Job

Returns a new instance of Job.



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

def initialize(conn, id, body)
  @conn = conn
  @id = id
  @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

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



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

def age() stats['age'] end

#bury(newpri = pri) ⇒ Object



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

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

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



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

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

#delayObject



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

def delay() stats['delay'] end

#deleteObject



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

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

#inspectObject



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

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

#priObject



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

def pri() stats['pri'] end

#put_back(pri = self.pri, delay = 0, ttr = self.ttr) ⇒ Object



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

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

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



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

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

#serverObject



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

def server()
  @conn.addr
end

#stateObject



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

def state() stats['state'] end

#statsObject



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

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

#time_leftObject



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

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

#timeoutsObject



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

def timeouts() stats['timeouts'] end

#to_sObject



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

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

#ttrObject



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

def ttr() stats['ttr'] 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