Class: Beaneater::Job
- Inherits:
-
Object
- Object
- Beaneater::Job
- Defined in:
- lib/beaneater/job/record.rb
Overview
Represents job related commands.
Instance Attribute Summary collapse
-
#body ⇒ String
The job's body.
-
#client ⇒ Object
Returns the value of attribute client.
-
#id ⇒ Integer
Id for the job.
-
#reserved ⇒ Boolean
Whether the job has been reserved.
Instance Method Summary collapse
-
#bury(options = {}) ⇒ Hash{Symbol => String,Number}
Sends command to bury a reserved job.
-
#delay ⇒ Integer
Returns the delay of this job.
-
#delete ⇒ Hash{Symbol => String,Number}
Sends command to delete a job.
-
#exists? ⇒ Boolean
Check if the job still exists.
-
#initialize(client, res) ⇒ Job
constructor
Initializes a new job object.
-
#kick ⇒ Hash{Symbol => String,Number}
Sends command to kick a buried job.
-
#pri ⇒ Integer
Returns the pri of this job.
-
#release(options = {}) ⇒ Hash{Symbol => String,Number}
Sends command to release a job back to ready state.
-
#reserved? ⇒ Boolean
Check if job is currently in a reserved state.
-
#stats ⇒ Beaneater::StatStruct
Sends command to get stats about job.
-
#to_s ⇒ String
(also: #inspect)
Returns string representation of job.
-
#touch ⇒ Hash{Symbol => String,Number}
Sends command to touch job which extends the ttr.
-
#transmit(cmd, &block) ⇒ Hash{Symbol => String,Number}
protected
Transmit command to beanstalkd instance and fetch response.
-
#ttr ⇒ Integer
Returns the ttr of this job.
-
#tube ⇒ String
Returns the name of the tube this job is in.
-
#with_reserved(cmd, &block) ⇒ Hash{Symbol => String,Number}
protected
Transmits a command which requires the job to be reserved.
Constructor Details
#initialize(client, res) ⇒ Job
Initializes a new job object.
20 21 22 23 24 25 |
# File 'lib/beaneater/job/record.rb', line 20 def initialize(client, res) @client = client @id = res[:id] @body = res[:body] @reserved = res[:status] == 'RESERVED' end |
Instance Attribute Details
#body ⇒ String
Returns the job's body.
13 |
# File 'lib/beaneater/job/record.rb', line 13 attr_reader :id, :body, :reserved, :client |
#client ⇒ Object
Returns the value of attribute client.
13 |
# File 'lib/beaneater/job/record.rb', line 13 attr_reader :id, :body, :reserved, :client |
#id ⇒ Integer
Returns id for the job.
13 14 15 |
# File 'lib/beaneater/job/record.rb', line 13 def id @id end |
#reserved ⇒ Boolean
Returns whether the job has been reserved.
13 |
# File 'lib/beaneater/job/record.rb', line 13 attr_reader :id, :body, :reserved, :client |
Instance Method Details
#bury(options = {}) ⇒ Hash{Symbol => String,Number}
Sends command to bury a reserved job.
38 39 40 41 42 43 |
# File 'lib/beaneater/job/record.rb', line 38 def bury(={}) = { :pri => stats.pri }.merge() with_reserved("bury #{id} #{[:pri]}") do @reserved = false end end |
#delay ⇒ Integer
Returns the delay of this job
178 179 180 |
# File 'lib/beaneater/job/record.rb', line 178 def delay self.stats.delay end |
#delete ⇒ Hash{Symbol => String,Number}
Sends command to delete a job.
83 84 85 |
# File 'lib/beaneater/job/record.rb', line 83 def delete transmit("delete #{id}") { @reserved = false } end |
#exists? ⇒ Boolean
Check if the job still exists.
130 131 132 133 134 |
# File 'lib/beaneater/job/record.rb', line 130 def exists? !self.stats.nil? rescue Beaneater::NotFoundError false end |
#kick ⇒ Hash{Symbol => String,Number}
Sends command to kick a buried job.
95 96 97 |
# File 'lib/beaneater/job/record.rb', line 95 def kick transmit("kick-job #{id}") end |
#pri ⇒ Integer
Returns the pri of this job
167 168 169 |
# File 'lib/beaneater/job/record.rb', line 167 def pri self.stats.pri end |
#release(options = {}) ⇒ Hash{Symbol => String,Number}
Sends command to release a job back to ready state.
56 57 58 59 60 61 |
# File 'lib/beaneater/job/record.rb', line 56 def release(={}) = { :pri => stats.pri, :delay => stats.delay }.merge() with_reserved("release #{id} #{[:pri]} #{[:delay]}") do @reserved = false end end |
#reserved? ⇒ Boolean
Check if job is currently in a reserved state.
119 120 121 |
# File 'lib/beaneater/job/record.rb', line 119 def reserved? @reserved || self.stats.state == "reserved" end |
#stats ⇒ Beaneater::StatStruct
Sends command to get stats about job.
107 108 109 110 |
# File 'lib/beaneater/job/record.rb', line 107 def stats res = transmit("stats-job #{id}") StatStruct.from_hash(res[:body]) end |
#to_s ⇒ String Also known as: inspect
Returns string representation of job
189 190 191 |
# File 'lib/beaneater/job/record.rb', line 189 def to_s "#<Beaneater::Job id=#{id} body=#{body.inspect}>" end |
#touch ⇒ Hash{Symbol => String,Number}
Sends command to touch job which extends the ttr.
71 72 73 |
# File 'lib/beaneater/job/record.rb', line 71 def touch with_reserved("touch #{id}") end |
#transmit(cmd, &block) ⇒ Hash{Symbol => String,Number} (protected)
Transmit command to beanstalkd instance and fetch response.
204 205 206 207 208 |
# File 'lib/beaneater/job/record.rb', line 204 def transmit(cmd, &block) res = client.connection.transmit(cmd) yield if block_given? res end |
#ttr ⇒ Integer
Returns the ttr of this job
156 157 158 |
# File 'lib/beaneater/job/record.rb', line 156 def ttr @ttr ||= self.stats.ttr end |
#tube ⇒ String
Returns the name of the tube this job is in
144 145 146 |
# File 'lib/beaneater/job/record.rb', line 144 def tube @tube ||= self.stats.tube end |
#with_reserved(cmd, &block) ⇒ Hash{Symbol => String,Number} (protected)
Transmits a command which requires the job to be reserved.
218 219 220 221 |
# File 'lib/beaneater/job/record.rb', line 218 def with_reserved(cmd, &block) raise JobNotReserved unless reserved? transmit(cmd, &block) end |