http_resque 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -0
- data/bin/http_resque +83 -0
- data/http_resque.gemspec +1 -1
- data/lib/http_resque/version.rb +1 -1
- metadata +9 -7
data/README.markdown
ADDED
data/bin/http_resque
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
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, off-box, for the purposes of integration testing background jobs. This is
|
5
|
+
# necessary because background jobs fail notoriously often in production and so they need integration -- not
|
6
|
+
# unit -- tests. This helps you to cleanly write those integration tests.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
# QUEUE=* http_resque -p 8080
|
10
|
+
# The server uses port 4567 by default. Use -p to specify an alternate port.
|
11
|
+
# You'll note that the QUEUE environment variable is used just like it is when running `rake resque:work`.
|
12
|
+
|
13
|
+
# Once it's started, you can access these URLs to manipulate jobs:
|
14
|
+
# GET /queues/:queue/jobs
|
15
|
+
# DELETE /queues/:queue/jobs
|
16
|
+
# POST /queues/:queue/jobs
|
17
|
+
# GET /queues/:queue/result_of_oldest_job
|
18
|
+
|
19
|
+
require "sinatra/base"
|
20
|
+
require "thin"
|
21
|
+
require "resque"
|
22
|
+
require "rake"
|
23
|
+
require "json"
|
24
|
+
|
25
|
+
# Load the Rakefile which should in turn require all of their Resque job classes.
|
26
|
+
# TODO(philc): The path to this Rakefile should be an argument.
|
27
|
+
load "./Rakefile"
|
28
|
+
|
29
|
+
class HttpResque < Sinatra::Base
|
30
|
+
settings.server = "thin"
|
31
|
+
|
32
|
+
STDOUT.sync = STDERR.sync = true
|
33
|
+
|
34
|
+
# Run rake resque:work in a background process. It will exit when this process exits.
|
35
|
+
fork { Rake::Task["resque:work"].invoke }
|
36
|
+
|
37
|
+
settings.port = ARGV.include?("-p") ? ARGV[ARGV.index("-p") + 1] : ENV["PORT"]
|
38
|
+
|
39
|
+
get "/" do
|
40
|
+
"http_resque is here."
|
41
|
+
end
|
42
|
+
|
43
|
+
# The Resque representation of up to 25 jobs in this queue, *oldest* first. Resque jobs look like this:
|
44
|
+
# { "class"=>"DeployBuild", "args"=>["my_embed_code", "my_youtube_synd_id"] }
|
45
|
+
get "/queues/:queue/jobs" do
|
46
|
+
(Resque.peek(params[:queue], 0, 25) || []).to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
delete "/queues/:queue/jobs" do
|
50
|
+
Resque.remove_queue(params[:queue])
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
# Create a new job.
|
55
|
+
# - queue: the queue to enqueue this job into.
|
56
|
+
# - arguments: optional; an array of arguments for the Resque job.
|
57
|
+
post "/queues/:queue/jobs" do
|
58
|
+
halt(400, "Provide a valid JSON body.") unless json_body
|
59
|
+
klass = json_body["class"]
|
60
|
+
halt(400, "Specify a class.") unless klass
|
61
|
+
klass = Object.const_get(klass)
|
62
|
+
Resque.enqueue_to(params[:queue], klass, *json_body["arguments"])
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# Executes the job at the head of this queue (the oldest job), and blocks until it's finished.
|
67
|
+
# This is useful for scripting integration tests which verify that a background job is working correctly.
|
68
|
+
get "/queues/:queue/result_of_oldest_job" do
|
69
|
+
job = Resque::Job.reserve(params[:queue])
|
70
|
+
halt(404, "No jobs left in #{params[:queue]}") unless job
|
71
|
+
begin
|
72
|
+
job.perform
|
73
|
+
rescue => error
|
74
|
+
halt(500, "This job raised an exception when run: " +
|
75
|
+
"#{job.inspect}\n#{error.class}: #{error.message}\n#{error.backtrace.join("\n")}")
|
76
|
+
end
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def json_body() @json_body ||= JSON.parse(request.body.read) rescue nil end
|
81
|
+
|
82
|
+
run! if app_file == $0
|
83
|
+
end
|
data/http_resque.gemspec
CHANGED
@@ -8,7 +8,7 @@ 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 = "A
|
11
|
+
s.summary = "A small HTTP wrapper around Resque, so you can schedule and test jobs over HTTP."
|
12
12
|
|
13
13
|
s.rubyforge_project = "http_resque"
|
14
14
|
|
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: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Phil Crosby
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03-
|
18
|
+
date: 2012-03-20 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -91,8 +91,8 @@ dependencies:
|
|
91
91
|
description:
|
92
92
|
email:
|
93
93
|
- phil.crosby@gmail.com
|
94
|
-
executables:
|
95
|
-
|
94
|
+
executables:
|
95
|
+
- http_resque
|
96
96
|
extensions: []
|
97
97
|
|
98
98
|
extra_rdoc_files: []
|
@@ -100,7 +100,9 @@ extra_rdoc_files: []
|
|
100
100
|
files:
|
101
101
|
- .gitignore
|
102
102
|
- Gemfile
|
103
|
+
- README.markdown
|
103
104
|
- Rakefile
|
105
|
+
- bin/http_resque
|
104
106
|
- http_resque.gemspec
|
105
107
|
- lib/http_resque.rb
|
106
108
|
- lib/http_resque/version.rb
|
@@ -137,6 +139,6 @@ rubyforge_project: http_resque
|
|
137
139
|
rubygems_version: 1.6.2
|
138
140
|
signing_key:
|
139
141
|
specification_version: 3
|
140
|
-
summary: A
|
142
|
+
summary: A small HTTP wrapper around Resque, so you can schedule and test jobs over HTTP.
|
141
143
|
test_files: []
|
142
144
|
|