Permalink
Browse files

Stasis::Server really working now

  • Loading branch information...
winton committed Aug 17, 2011
1 parent 048eccb commit ed6b6f16896c0b86bffa9045530b5d6934ac76b0
Showing with 19 additions and 16 deletions.
  1. +2 −2 README.md
  2. +1 −1 lib/stasis.rb
  3. +16 −13 lib/stasis/server.rb
View
@@ -266,8 +266,8 @@ Push to the server (in Ruby):
# Locals for `before` callbacks, views, and helpers
:locals => { :x => 'y' },
- # redis-rb instance
- :redis => Redis.connect,
+ # Redis address
+ :redis => "localhost:6379/0",
# Return rendered templates (false by default)
:return => true,
View
@@ -200,7 +200,7 @@ def render(*only)
# Add `destination` (as specified from `Stasis.new`) to front of relative
# destination.
- dest = "#{destination}#{dest}"
+ dest = "#{destination}#{relative}"
# Cut off the extension if the extension is supported by [Tilt][ti].
dest =
View
@@ -20,18 +20,15 @@ def initialize(root, options={})
if request
request = Yajl::Parser.parse(request)
- files = nil
puts request.inspect
- stasis.render(*request['paths'], :locals => request['locals'])
+ files = stasis.render(
+ *request['paths'],
+ :collect => request['return'],
+ :locals => request['locals']
+ )
if request['return'] && request['paths'] && !request['paths'].empty?
- files = request['paths'].inject({}) do |hash, path|
- path = "#{root}/public/#{path}"
- puts path
- hash[path] = File.read(path) if File.file?(path)
- hash
- end
request['wait'] = true
end
@@ -63,24 +60,30 @@ def shut_down
class <<self
def push(options)
options[:id] = Digest::SHA1.hexdigest("#{options['paths']}#{Random.rand}")
- redis = options.delete(:redis)
+ redis_url = "redis://#{options.delete(:redis) || "localhost:6379/0"}"
response = nil
- redis.rpush("stasis:requests", Yajl::Encoder.encode(options))
+ redis_1 = Redis.connect(:url => redis_url)
+ redis_2 = Redis.connect(:url => redis_url)
if options[:return] || options[:wait]
- redis.subscribe(response_key(options[:id])) do |on|
+ redis_1.subscribe(response_key(options[:id])) do |on|
on.subscribe do |channel, subscriptions|
-
+ redis_2.rpush("stasis:requests", Yajl::Encoder.encode(options))
end
on.message do |channel, message|
response = Yajl::Parser.parse(message)
- redis.unsubscribe
+ redis_1.unsubscribe
end
end
+ else
+ redis_1.rpush("stasis:requests", Yajl::Encoder.encode(options))
end
+ redis_1.quit
+ redis_2.quit
+
response
end

0 comments on commit ed6b6f1

Please sign in to comment.