rack-worker 0.0.1.alpha2 → 0.0.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/worker.rb +18 -3
- data/lib/rack/worker/version.rb +1 -1
- metadata +1 -1
data/lib/rack/worker.rb
CHANGED
@@ -10,13 +10,28 @@ module Rack
|
|
10
10
|
self.class.cache
|
11
11
|
end
|
12
12
|
|
13
|
+
def queue
|
14
|
+
self.class.queue
|
15
|
+
end
|
16
|
+
|
13
17
|
def self.cache
|
14
|
-
@cache
|
18
|
+
return @cache if defined? @cache
|
19
|
+
@cache = ::Dalli::Client.new if defined?(::Dalli)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.queue
|
23
|
+
(defined?(@queue) && @queue) || (defined?(QC) && QC)
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
attr_writer :queue
|
28
|
+
attr_writer :cache
|
15
29
|
end
|
16
30
|
|
17
31
|
def call(env)
|
18
32
|
# so when worker calls app we don't return 204
|
19
|
-
|
33
|
+
# or if there is no cache just pass the request through
|
34
|
+
return @app.call(env) if env['rack.worker_qc'] || !cache
|
20
35
|
|
21
36
|
if env['REQUEST_METHOD'] == 'GET'
|
22
37
|
key = key(env)
|
@@ -25,7 +40,7 @@ module Rack
|
|
25
40
|
else
|
26
41
|
unless cache.get("env-#{key}")
|
27
42
|
cache.set("env-#{key}", env.to_json)
|
28
|
-
|
43
|
+
queue.enqueue("#{self.class.name}.process_request",
|
29
44
|
@app.class.name, key)
|
30
45
|
end
|
31
46
|
[202, {"Content-type" => "text/plain"}, []]
|
data/lib/rack/worker/version.rb
CHANGED