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 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 ||= defined?(::Dalli) ? ::Dalli::Client.new : nil
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
- return @app.call(env) if env['rack.worker_qc']
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
- QC.enqueue("#{self.class.name}.process_request",
43
+ queue.enqueue("#{self.class.name}.process_request",
29
44
  @app.class.name, key)
30
45
  end
31
46
  [202, {"Content-type" => "text/plain"}, []]
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Worker
3
- VERSION = '0.0.1.alpha2'
3
+ VERSION = '0.0.1.rc1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha2
4
+ version: 0.0.1.rc1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: