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.
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, body) ⇒ Job
constructor
A new instance of Job.
- #inspect ⇒ Object
- #pri ⇒ Object
- #put_back(pri = self.pri, delay = 0, ttr = self.ttr) ⇒ Object
- #release(newpri = pri, delay = 0) ⇒ Object
- #server ⇒ Object
- #state ⇒ Object
- #stats ⇒ Object
- #time_left ⇒ Object
- #timeouts ⇒ Object
- #to_s ⇒ Object
- #ttr ⇒ Object
-
#ybody ⇒ Object
Return the object that results from loading the body as a yaml stream.
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
#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 |
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
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 |
#delay ⇒ Object
71 |
# File 'lib/beanstalk-client/job.rb', line 71 def delay() stats['delay'] end |
#delete ⇒ Object
46 47 48 49 |
# File 'lib/beanstalk-client/job.rb', line 46 def delete() @conn.delete(id) if !@deleted @deleted = true end |
#inspect ⇒ Object
91 92 93 |
# File 'lib/beanstalk-client/job.rb', line 91 def inspect "(job server=#{server} id=#{id} size=#{body.size})" end |
#pri ⇒ Object
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 |
#server ⇒ Object
75 76 77 |
# File 'lib/beanstalk-client/job.rb', line 75 def server() @conn.addr end |
#state ⇒ Object
70 |
# File 'lib/beanstalk-client/job.rb', line 70 def state() stats['state'] end |
#stats ⇒ Object
63 64 65 |
# File 'lib/beanstalk-client/job.rb', line 63 def stats() @conn.job_stats(id) end |
#time_left ⇒ Object
68 |
# File 'lib/beanstalk-client/job.rb', line 68 def time_left() stats['time-left'] end |
#timeouts ⇒ Object
67 |
# File 'lib/beanstalk-client/job.rb', line 67 def timeouts() stats['timeouts'] end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/beanstalk-client/job.rb', line 87 def to_s "(job #{body.inspect})" end |
#ttr ⇒ Object
73 |
# File 'lib/beanstalk-client/job.rb', line 73 def ttr() stats['ttr'] 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 |