Class: Beanstalk::Job
- Inherits:
-
Object
- Object
- Beanstalk::Job
- 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
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#pri ⇒ Object
readonly
Returns the value of attribute pri.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Convenience method for getting ybody elements.
-
#[]=(name, val) ⇒ Object
Convenience method for setting ybody elements.
- #age ⇒ Object
- #bury(newpri = pri) ⇒ Object
- #decay(d = ([1, delay].max * 1.3).ceil) ⇒ Object
- #delay ⇒ Object
- #delete ⇒ Object
-
#initialize(conn, id, pri, body) ⇒ Job
constructor
A new instance of Job.
- #inspect ⇒ Object
- #put_back(pri = self.pri) ⇒ Object
- #release(newpri = pri, delay = 0) ⇒ Object
- #server ⇒ Object
- #state ⇒ Object
- #stats ⇒ Object
- #time_left ⇒ Object
- #timeouts ⇒ Object
- #to_s ⇒ Object
-
#ybody ⇒ Object
Return the object that results from loading the body as a yaml stream.
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
21 22 23 |
# File 'lib/beanstalk-client/job.rb', line 21 def body @body end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
21 22 23 |
# File 'lib/beanstalk-client/job.rb', line 21 def conn @conn end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/beanstalk-client/job.rb', line 21 def id @id end |
#pri ⇒ Object (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 |
#age ⇒ Object
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 |
#delay ⇒ Object
72 |
# File 'lib/beanstalk-client/job.rb', line 72 def delay() stats.fetch('delay', 0) end |
#delete ⇒ Object
47 48 49 50 |
# File 'lib/beanstalk-client/job.rb', line 47 def delete() @conn.delete(id) if !@deleted @deleted = true end |
#inspect ⇒ Object
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 |
#server ⇒ Object
74 75 76 |
# File 'lib/beanstalk-client/job.rb', line 74 def server() @conn.addr end |
#state ⇒ Object
71 |
# File 'lib/beanstalk-client/job.rb', line 71 def state() stats['state'] end |
#stats ⇒ Object
64 65 66 |
# File 'lib/beanstalk-client/job.rb', line 64 def stats() @conn.job_stats(id) end |
#time_left ⇒ Object
69 |
# File 'lib/beanstalk-client/job.rb', line 69 def time_left() stats['time-left'] end |
#timeouts ⇒ Object
68 |
# File 'lib/beanstalk-client/job.rb', line 68 def timeouts() stats['timeouts'] end |
#to_s ⇒ Object
86 87 88 |
# File 'lib/beanstalk-client/job.rb', line 86 def to_s "(job #{body.inspect})" end |
#ybody ⇒ Object
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 |