Class: Beanstalk::Connection
- Inherits:
-
Object
- Object
- Beanstalk::Connection
show all
- Defined in:
- lib/beanstalk-client/connection.rb
Overview
Same interface as RawConnection. With this you can reserve more than one job at a time.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(addr, jptr = self) ⇒ Connection
Returns a new instance of Connection.
187
188
189
190
191
192
|
# File 'lib/beanstalk-client/connection.rb', line 187
def initialize(addr, jptr=self)
@addr = addr
@misc = RawConnection.new(addr, jptr)
@free = Bag.new{RawConnection.new(addr, jptr)}
@used = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(selector, *args, &block) ⇒ Object
218
219
220
|
# File 'lib/beanstalk-client/connection.rb', line 218
def method_missing(selector, *args, &block)
@misc.send(selector, *args, &block)
end
|
Instance Attribute Details
#addr ⇒ Object
Returns the value of attribute addr.
185
186
187
|
# File 'lib/beanstalk-client/connection.rb', line 185
def addr
@addr
end
|
Instance Method Details
#bury(id, pri) ⇒ Object
213
214
215
216
|
# File 'lib/beanstalk-client/connection.rb', line 213
def bury(id, pri)
@used[id].bury(id, pri)
@free.give(@used.delete(id))
end
|
#delete(id) ⇒ Object
203
204
205
206
|
# File 'lib/beanstalk-client/connection.rb', line 203
def delete(id)
@used[id].delete(id)
@free.give(@used.delete(id))
end
|
#release(id, pri, delay) ⇒ Object
208
209
210
211
|
# File 'lib/beanstalk-client/connection.rb', line 208
def release(id, pri, delay)
@used[id].release(id, pri, delay)
@free.give(@used.delete(id))
end
|
#reserve ⇒ Object
194
195
196
197
198
199
200
201
|
# File 'lib/beanstalk-client/connection.rb', line 194
def reserve()
c = @free.take()
j = c.reserve()
@used[j.id] = c
j
ensure
@free.give(c) if c and not j
end
|