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.
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ notifications:
6
+ email:
7
+ - csquared@heroku.com
8
+
data/Gemfile CHANGED
@@ -4,8 +4,8 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
+ gem 'rake'
7
8
  gem 'rr'
8
- gem 'turn'
9
9
  gem 'webmock'
10
10
  gem 'rack-test', :require => 'rack/test'
11
11
  gem 'sinatra', :require => 'sinatra/base'
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Rack::Worker
2
2
 
3
- Rack middleware that implements the Worker Pattern.
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 `set(key, string)`
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
@@ -1,2 +1,11 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -40,7 +40,7 @@ module Rack
40
40
  response
41
41
  else
42
42
  unless cache.get("env-#{key}")
43
- cache.set("env-#{key}", env.to_json)
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.set("response-#{key}", [status, headers, body].to_json)
66
+ cache.add("response-#{key}", [status, headers, body].to_json)
67
67
  end
68
68
 
69
69
  def get_response(key)
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Worker
3
- VERSION = '0.0.1.rc3'
3
+ VERSION = '0.0.1.rc4'
4
4
  end
5
5
  end
@@ -11,4 +11,7 @@ class Rack::Worker::TestCase < Test::Unit::TestCase
11
11
  super
12
12
  WebMock.reset!
13
13
  end
14
+ def default_test
15
+ #fu test::unit
16
+ end
14
17
  end
@@ -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).set('env-/foo?', is_a(String))
10
- mock(Rack::Worker.cache).set('response-/foo?', is_a(String))
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).set
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.rc3
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 00:00:00.000000000 Z
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: &70334749515180 !ruby/object:Gem::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: *70334749515180
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