Skip to content

Commit 17c5f76

Browse files
author
Adam Wiggins
committed
BEANSTALK_URL env var to specify location of beanstalkd
1 parent 77dab5a commit 17c5f76

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/stalker.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'beanstalk-client'
22
require 'json'
3+
require 'uri'
34

45
module Stalker
56
extend self
@@ -80,7 +81,19 @@ def find_priority(job)
8081
end
8182

8283
def beanstalk
83-
@@beanstalk ||= Beanstalk::Pool.new([ 'localhost:11300' ])
84+
@@beanstalk ||= Beanstalk::Pool.new([ beanstalk_host_and_port ])
85+
end
86+
87+
def beanstalk_url
88+
ENV['BEANSTALK_URL'] || 'beanstalk://localhost:11300/'
89+
end
90+
91+
class BadURL < RuntimeError; end
92+
93+
def beanstalk_host_and_port
94+
uri = URI.parse(beanstalk_url)
95+
raise(BadURL, beanstalk_url) if uri.scheme != 'beanstalk'
96+
return "#{uri.host}:#{uri.port}"
8497
end
8598

8699
def exception_message(e)

0 commit comments

Comments
 (0)