Class: Sabbath::Backend::Beanstalk
- Inherits:
-
Object
- Object
- Sabbath::Backend::Beanstalk
- Defined in:
- lib/sabbath/backend/beanstalk.rb
Constant Summary collapse
- Name =
'Beanstalkd'.freeze
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #connection(id, tube = 'default') ⇒ Object
- #create_job(conn_id, tube, body, &block) ⇒ Object
- #delete_job(conn_id, tube, id, &block) ⇒ Object
- #get_job(conn_idtube, id, &block) ⇒ Object
- #get_latest_job(conn_id, tube, timeout = nil, &block) ⇒ Object
-
#initialize(host, port) ⇒ Beanstalk
constructor
A new instance of Beanstalk.
- #name ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Beanstalk
Returns a new instance of Beanstalk.
15 16 17 18 |
# File 'lib/sabbath/backend/beanstalk.rb', line 15 def initialize(host, port) @host, @port = host, port @conns = {} end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/sabbath/backend/beanstalk.rb', line 7 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/sabbath/backend/beanstalk.rb', line 7 def port @port end |
Instance Method Details
#connection(id, tube = 'default') ⇒ Object
20 21 22 |
# File 'lib/sabbath/backend/beanstalk.rb', line 20 def connection(id, tube = 'default') @conns[id] ||= EM::Beanstalk.new(:host => host, :port => port, :tube => tube, :retry_count => 0, :raise_on_disconnect => false) end |
#create_job(conn_id, tube, body, &block) ⇒ Object
32 33 34 |
# File 'lib/sabbath/backend/beanstalk.rb', line 32 def create_job(conn_id, tube, body, &block) connection(conn_id, tube).put(body, &block) end |
#delete_job(conn_id, tube, id, &block) ⇒ Object
36 37 38 39 |
# File 'lib/sabbath/backend/beanstalk.rb', line 36 def delete_job(conn_id, tube, id, &block) puts "deleting job #{tube.inspect} #{id.inspect}" connection(conn_id, tube).delete(id, &block) end |
#get_job(conn_idtube, id, &block) ⇒ Object
28 29 30 |
# File 'lib/sabbath/backend/beanstalk.rb', line 28 def get_job(conn_idtube, id, &block) connection(conn_id, tube).peek(id, &block) end |
#get_latest_job(conn_id, tube, timeout = nil, &block) ⇒ Object
24 25 26 |
# File 'lib/sabbath/backend/beanstalk.rb', line 24 def get_latest_job(conn_id, tube, timeout = nil, &block) connection(conn_id, tube).reserve(timeout, &block) end |
#name ⇒ Object
11 12 13 |
# File 'lib/sabbath/backend/beanstalk.rb', line 11 def name Name end |