rack-worker 0.0.1.rc3 → 0.0.1.rc4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -0
- data/Gemfile +1 -1
- data/README.md +28 -2
- data/Rakefile +9 -0
- data/lib/rack/worker.rb +2 -2
- data/lib/rack/worker/version.rb +1 -1
- data/test/test_helper.rb +3 -0
- data/test/worker_test.rb +3 -3
- metadata +5 -4
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Rack::Worker
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://secure.travis-ci.org/csquared/rack-worker.png)](http://travis-ci.org/csquared/rack-worker)
|
4
|
+
|
5
|
+
Rack middleware that implements the [Worker Pattern](https://ryandotsmith.heroku.com/worker-pattern).
|
4
6
|
|
5
7
|
It processes GET requests with a worker backend and only serves them straight from a cache.
|
6
8
|
While processing the request it serves empty HTTP 202 responses.
|
@@ -60,13 +62,37 @@ See configuration for setting an expiry time on records.
|
|
60
62
|
```ruby
|
61
63
|
Rack::Worker.cache = Dalli::Client.new(nil, {:expires_in => 300})
|
62
64
|
```
|
63
|
-
The `cache` can be anything that responds to `get(key)` and `
|
65
|
+
The `cache` can be anything that responds to `get(key)` and `add(key, string)`
|
64
66
|
|
65
67
|
```ruby
|
66
68
|
Rack::Worker.queue = QC
|
67
69
|
```
|
68
70
|
The `queue` can be anything that responds to `enqueue(method, *params)`
|
69
71
|
|
72
|
+
## Clients
|
73
|
+
|
74
|
+
Here's an example of a polling GET request in javascript using jQuery:
|
75
|
+
|
76
|
+
```javascript
|
77
|
+
Lib.get = function(path, params, callback) {
|
78
|
+
var success_callback = function(data, textStatus, xhr){
|
79
|
+
if(xhr.status == 202){
|
80
|
+
setTimeout(function() {
|
81
|
+
return Lib.get(path, params, callback)
|
82
|
+
}, 500)
|
83
|
+
}else{
|
84
|
+
return callback(data)
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
$.ajax({
|
89
|
+
url: path,
|
90
|
+
success: success_callback,
|
91
|
+
'data': params,
|
92
|
+
dataType: 'json'
|
93
|
+
})
|
94
|
+
}
|
95
|
+
```
|
70
96
|
|
71
97
|
## Contributing
|
72
98
|
|
data/Rakefile
CHANGED
data/lib/rack/worker.rb
CHANGED
@@ -40,7 +40,7 @@ module Rack
|
|
40
40
|
response
|
41
41
|
else
|
42
42
|
unless cache.get("env-#{key}")
|
43
|
-
cache.
|
43
|
+
cache.add("env-#{key}", env.to_json)
|
44
44
|
name = @app.is_a?(Class) ? @app.name : @app.class.name
|
45
45
|
queue.enqueue("#{self.class.name}.process_request", name, key)
|
46
46
|
end
|
@@ -63,7 +63,7 @@ module Rack
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def self.set_response(key, status, headers, body)
|
66
|
-
cache.
|
66
|
+
cache.add("response-#{key}", [status, headers, body].to_json)
|
67
67
|
end
|
68
68
|
|
69
69
|
def get_response(key)
|
data/lib/rack/worker/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/worker_test.rb
CHANGED
@@ -6,8 +6,8 @@ module QueueTest
|
|
6
6
|
mock(Rack::Worker.cache).get('response-/foo?') { false }
|
7
7
|
mock(Rack::Worker.cache).get('env-/foo?') { false }
|
8
8
|
mock(Rack::Worker.cache).get('env-/foo?') { {'rack.input' => []}.to_json }
|
9
|
-
mock(Rack::Worker.cache).
|
10
|
-
mock(Rack::Worker.cache).
|
9
|
+
mock(Rack::Worker.cache).add('env-/foo?', is_a(String))
|
10
|
+
mock(Rack::Worker.cache).add('response-/foo?', is_a(String))
|
11
11
|
|
12
12
|
mock_queue = Object.new
|
13
13
|
def mock_queue.enqueue(function_call, *args)
|
@@ -39,7 +39,7 @@ class WorkerTest < Rack::Worker::TestCase
|
|
39
39
|
Rack::Worker.cache = Object.new
|
40
40
|
mock(Rack::Worker.cache).get('response-/foo?') { false }
|
41
41
|
mock(Rack::Worker.cache).get('env-/foo?') { false }
|
42
|
-
stub(Rack::Worker.cache).
|
42
|
+
stub(Rack::Worker.cache).add
|
43
43
|
|
44
44
|
Rack::Worker.queue = Object.new
|
45
45
|
mock(Rack::Worker.queue).enqueue('Rack::Worker.process_request', is_a(String), '/foo?')
|
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.
|
4
|
+
version: 0.0.1.rc4
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70188854844840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70188854844840
|
25
25
|
description: Rack middleware that implements the Worker Pattern
|
26
26
|
email:
|
27
27
|
- christopher.continanza@gmail.com
|
@@ -30,6 +30,7 @@ extensions: []
|
|
30
30
|
extra_rdoc_files: []
|
31
31
|
files:
|
32
32
|
- .gitignore
|
33
|
+
- .travis.yml
|
33
34
|
- Gemfile
|
34
35
|
- LICENSE
|
35
36
|
- README.md
|