http_resque 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +81 -2
- data/bin/http_resque +35 -22
- data/http_resque.gemspec +5 -1
- data/lib/http_resque.rb +1 -1
- data/lib/http_resque/version.rb +1 -1
- metadata +19 -5
data/README.markdown
CHANGED
@@ -1,3 +1,82 @@
|
|
1
|
-
|
1
|
+
http_resque
|
2
2
|
===========
|
3
|
-
|
3
|
+
http_resque helps you cleanly write integration tests for your Resque jobs. It's a thin HTTP API around the
|
4
|
+
Resque daemon. With it you can manipulate the contents of the Resque queues using HTTP requests.
|
5
|
+
|
6
|
+
This is a key ingredient for writing off-box integration tests for your background jobs. In addition to inspecting and clearing queues, you can run a Resque job _synchronously_. This allows you to test that your
|
7
|
+
background jobs are working by making HTTP requests, which is the same simple way you'd test a running webapp or a RESTful API server.
|
8
|
+
|
9
|
+
Making your background jobs easier to integration test is important -- background jobs are prone to failure
|
10
|
+
because they run in the background, and frequently have environment-related bugs in production. Unit tests
|
11
|
+
usually aren't good enough.
|
12
|
+
|
13
|
+
Installation & Usage
|
14
|
+
--------------------
|
15
|
+
|
16
|
+
gem install http_resque
|
17
|
+
|
18
|
+
QUEUE=* http_resque
|
19
|
+
|
20
|
+
or if you use Bundler:
|
21
|
+
QUEUE=* bundle exec http_resque
|
22
|
+
|
23
|
+
Optional command line arguments:
|
24
|
+
|
25
|
+
$ http_resque -h
|
26
|
+
-p: the port to listen on. Defaults to the $PORT environment variable, or 4568.
|
27
|
+
--rakefile: the location of your Rakefile. The default is "./Rakefile".
|
28
|
+
|
29
|
+
When run, http_resque starts a small web server and then invokes `rake resque:work` in a fork.
|
30
|
+
|
31
|
+
REST APIs for Resque
|
32
|
+
--------------------
|
33
|
+
|
34
|
+
Once the http_resque server is started, you can access these URLs to manipulate your background jobs:
|
35
|
+
|
36
|
+
### GET /queues/:queue_name/jobs
|
37
|
+
|
38
|
+
Lists all jobs in the queue named "queue_name", oldest first.
|
39
|
+
|
40
|
+
$ curl localhost:4568/queues/my_test_queue/jobs
|
41
|
+
|
42
|
+
Response:
|
43
|
+
[
|
44
|
+
{ "class" => "EmailComment", "args" => ["jack_sparrow@pirates.net"] },
|
45
|
+
...
|
46
|
+
]
|
47
|
+
|
48
|
+
### DELETE /queues/:queue_name/jobs
|
49
|
+
|
50
|
+
Deletes all jobs in the given queue.
|
51
|
+
|
52
|
+
$ curl -X DELETE localhost:4568/queues/my_test_queue/jobs
|
53
|
+
|
54
|
+
### POST /queues/:queue_name/jobs
|
55
|
+
|
56
|
+
Create a new background job. The body of the request should be in JSON and include "class" and "arguments".
|
57
|
+
|
58
|
+
$ curl -X POST localhost:4568/queues/my_test_queue/jobs \
|
59
|
+
-d '{ "class": "EmailComment", "arguments":["jack_sparrow@pirates.net"] }'
|
60
|
+
|
61
|
+
### GET /queues/:queue_name/result_of_oldest_job
|
62
|
+
|
63
|
+
Runs the oldest job on the given queue, and does not return until it's finished. If there was a problem
|
64
|
+
running the job (like the job threw a Ruby exception), this will return a 500 status code with the exception
|
65
|
+
details.
|
66
|
+
|
67
|
+
$ curl localhost:4568/queues/my_test_queue/result_of_oldest_job
|
68
|
+
|
69
|
+
A response with a status of:
|
70
|
+
200 if successful.
|
71
|
+
404 if there are no jobs in this queue.
|
72
|
+
500 if there was an error running the job.
|
73
|
+
|
74
|
+
For further details, look at the web server's code in [bin/http_resque](https://github.com/philc/http_resque/blob/master/bin/http_resque). The code is shorter than this README.
|
75
|
+
|
76
|
+
Contribute
|
77
|
+
----------
|
78
|
+
http_resque is pretty small and limited as is. If you need more CLI options or a different set of REST APIs, file an issue or send a pull request.
|
79
|
+
|
80
|
+
Related
|
81
|
+
-------
|
82
|
+
[remote_http_testing](https://github.com/ooyala/remote_http_testing) - a small library for making remote HTTP requests and response assertions in tests.
|
data/bin/http_resque
CHANGED
@@ -1,40 +1,54 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
#
|
3
3
|
# This wraps the Resque process with a thin HTTP API which enables you to manipulate jobs using HTTP requests
|
4
|
-
# and run jobs synchronously,
|
5
|
-
#
|
6
|
-
# unit -- tests. This helps you to cleanly write those integration tests.
|
4
|
+
# and run jobs synchronously, for the purposes of integration testing background jobs. See the README for
|
5
|
+
# more details of why this is awesome.
|
7
6
|
#
|
8
7
|
# Usage:
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
8
|
+
# QUEUE=* http_resque
|
9
|
+
# Options:
|
10
|
+
# -p: the port to listen on. Defaults to the $PORT environment variable, or 4568.
|
11
|
+
# --rakefile: the location of your Rakefile. The default is "./Rakefile".
|
12
|
+
#
|
13
13
|
# Once it's started, you can access these URLs to manipulate jobs:
|
14
|
-
# GET /queues/:
|
15
|
-
# DELETE /queues/:
|
16
|
-
# POST /queues/:
|
17
|
-
# GET /queues/:
|
14
|
+
# GET /queues/:queue_name/jobs
|
15
|
+
# DELETE /queues/:queue_name/jobs
|
16
|
+
# POST /queues/:queue_name/jobs
|
17
|
+
# GET /queues/:queue_name/result_of_oldest_job
|
18
18
|
|
19
19
|
require "sinatra/base"
|
20
20
|
require "thin"
|
21
21
|
require "resque"
|
22
22
|
require "rake"
|
23
23
|
require "json"
|
24
|
+
require "trollop"
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
class HttpResqueServer < Sinatra::Base
|
27
|
+
cli_options = Trollop::options do
|
28
|
+
opt :rakefile, "The location of your Rakefile which loads your Resque workers.", :default => "./Rakefile"
|
29
|
+
opt :port, "The port this server should listen on."
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
unless ENV["QUEUE"]
|
33
|
+
puts "You must set the QUEUE env var, just as you would when running `QUEUE=* rake resque:work`."
|
34
|
+
exit 1
|
35
|
+
end
|
31
36
|
|
32
37
|
STDOUT.sync = STDERR.sync = true
|
33
38
|
|
39
|
+
begin
|
40
|
+
# Load their Rakefile, which should in turn require all of their Resque job classes.
|
41
|
+
load cli_options[:rakefile]
|
42
|
+
rescue LoadError
|
43
|
+
puts "Error loading Rakefile: #{cli_options[:rakefile]}. Give the path to your Rakefile using --rakefile."
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
|
34
47
|
# Run rake resque:work in a background process. It will exit when this process exits.
|
35
48
|
fork { Rake::Task["resque:work"].invoke }
|
36
49
|
|
37
|
-
settings.port =
|
50
|
+
settings.port = cli_options[:port] || ENV["PORT"] || 4568
|
51
|
+
settings.server = "thin"
|
38
52
|
|
39
53
|
get "/" do
|
40
54
|
"http_resque is here."
|
@@ -56,9 +70,8 @@ class HttpResque < Sinatra::Base
|
|
56
70
|
# - arguments: optional; an array of arguments for the Resque job.
|
57
71
|
post "/queues/:queue/jobs" do
|
58
72
|
halt(400, "Provide a valid JSON body.") unless json_body
|
59
|
-
|
60
|
-
|
61
|
-
klass = Object.const_get(klass)
|
73
|
+
halt(400, "Specify a class.") unless json_body["class"]
|
74
|
+
klass = Object.const_get(json_body["class"])
|
62
75
|
Resque.enqueue_to(params[:queue], klass, *json_body["arguments"])
|
63
76
|
nil
|
64
77
|
end
|
@@ -79,5 +92,5 @@ class HttpResque < Sinatra::Base
|
|
79
92
|
|
80
93
|
def json_body() @json_body ||= JSON.parse(request.body.read) rescue nil end
|
81
94
|
|
82
|
-
run! if app_file == $0
|
95
|
+
run! if File.basename(app_file) == File.basename($0)
|
83
96
|
end
|
data/http_resque.gemspec
CHANGED
@@ -8,7 +8,10 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Phil Crosby"]
|
9
9
|
s.email = ["phil.crosby@gmail.com"]
|
10
10
|
s.homepage = "http://github.com/philc/http_resque"
|
11
|
-
s.summary = "
|
11
|
+
s.summary = "Schedule and test Resque jobs using HTTP requests."
|
12
|
+
s.description = "http_resque helps you cleanly write integration tests for your Resque jobs. It's a thin " +
|
13
|
+
"HTTP API around the Resque daemon. With it you can manipulate the contents of the Resque queues " +
|
14
|
+
"using HTTP requests."
|
12
15
|
|
13
16
|
s.rubyforge_project = "http_resque"
|
14
17
|
|
@@ -22,4 +25,5 @@ Gem::Specification.new do |s|
|
|
22
25
|
s.add_runtime_dependency "rake"
|
23
26
|
s.add_runtime_dependency "json"
|
24
27
|
s.add_runtime_dependency "sinatra"
|
28
|
+
s.add_runtime_dependency "trollop"
|
25
29
|
end
|
data/lib/http_resque.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "
|
1
|
+
require "http_resque/version"
|
data/lib/http_resque/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_resque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Phil Crosby
|
@@ -88,7 +88,21 @@ dependencies:
|
|
88
88
|
version: "0"
|
89
89
|
type: :runtime
|
90
90
|
version_requirements: *id005
|
91
|
-
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: trollop
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :runtime
|
104
|
+
version_requirements: *id006
|
105
|
+
description: http_resque helps you cleanly write integration tests for your Resque jobs. It's a thin HTTP API around the Resque daemon. With it you can manipulate the contents of the Resque queues using HTTP requests.
|
92
106
|
email:
|
93
107
|
- phil.crosby@gmail.com
|
94
108
|
executables:
|
@@ -139,6 +153,6 @@ rubyforge_project: http_resque
|
|
139
153
|
rubygems_version: 1.6.2
|
140
154
|
signing_key:
|
141
155
|
specification_version: 3
|
142
|
-
summary:
|
156
|
+
summary: Schedule and test Resque jobs using HTTP requests.
|
143
157
|
test_files: []
|
144
158
|
|