swagger 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -11
- data/VERSION +1 -1
- data/lib/redis_impersonator.rb +9 -5
- data/lib/resque_extension.rb +1 -1
- data/spec/redis_impersonator_spec.rb +16 -0
- data/swagger.gemspec +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,22 +1,26 @@
|
|
1
|
-
=
|
1
|
+
= Swagger = Resque + ActiveRecord - Redis
|
2
2
|
|
3
|
-
Swagger allows you to use Resque
|
4
|
-
|
5
|
-
Resque is a great library for creating/running/administering background jobs. Redis is great too but may be overkill for just a few simple background jobs. Swagger marries the power and robustness of Resque with the trivial setup of delayed_job.
|
3
|
+
Swagger marries the power and robustness of Resque with the trivial setup of delayed_job. Swagger allows you to use all the features of Resque (http://github.com/defunkt/resque) without any of the "Redis" by adding one table to your existing database.
|
6
4
|
|
7
5
|
== Getting Started
|
8
6
|
|
9
|
-
1. Add resque and swagger to your gem dependencies (order is important)
|
7
|
+
=== 1. Add resque and swagger to your gem dependencies (order is important)
|
10
8
|
|
11
9
|
config.gem 'resque'
|
12
10
|
config.gem 'swagger'
|
13
11
|
|
14
|
-
2. In your rails app, create the file initializers/resque.rb with the following:
|
12
|
+
=== 2. In your rails app, create the file initializers/resque.rb with the following:
|
13
|
+
|
14
|
+
environment = ENV['RAILS_ENV'] || 'development'
|
15
|
+
database = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), '..', 'database.yml'))).result)[environment]
|
15
16
|
|
16
|
-
|
17
|
-
Resque.
|
17
|
+
require 'swagger'
|
18
|
+
Resque.swagger!
|
19
|
+
Resque.connect_to_database(database)
|
20
|
+
|
21
|
+
==== NOTE: This allows rails and the resque admin app to use the same initializer by executing at the console: resque-web config/initializers/resque.rb
|
18
22
|
|
19
|
-
3. Create an active record migration
|
23
|
+
=== 3. Create an active record migration
|
20
24
|
|
21
25
|
create_table :resque_values do |table|
|
22
26
|
table.column :key, :string
|
@@ -27,8 +31,6 @@ Resque is a great library for creating/running/administering background jobs. Re
|
|
27
31
|
add_index :resque_values, :key
|
28
32
|
add_index :resque_values, [:key, :key_type]
|
29
33
|
|
30
|
-
NOTE: To start up the administration sinatra app with swagger, do the following: resque-web config/initializers/resque.rb
|
31
|
-
|
32
34
|
== Note on Patches/Pull Requests
|
33
35
|
|
34
36
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/redis_impersonator.rb
CHANGED
@@ -84,15 +84,19 @@ class RedisImpersonator
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def lrange(list_name, start_range, end_range)
|
87
|
-
|
88
|
-
:conditions => {
|
87
|
+
options = { :conditions => {
|
89
88
|
:key => list_name.to_s,
|
90
|
-
:key_type=> LIST}
|
91
|
-
|
92
|
-
|
89
|
+
:key_type=> LIST}}
|
90
|
+
options.merge!(:limit => end_range, :offset => start_range) unless end_range < 0
|
91
|
+
values = ResqueValue.all(options)
|
93
92
|
values.map(&:value)
|
94
93
|
end
|
95
94
|
|
95
|
+
def lrem(list_name, count, value)
|
96
|
+
raise "Only supports count of 0 which means to remove all elements in list" if count != 0
|
97
|
+
ResqueValue.delete_all(:key => list_name.to_s, :key_type=> LIST, :value => value )
|
98
|
+
end
|
99
|
+
|
96
100
|
def lpop(list_name)
|
97
101
|
last = ResqueValue.last(:conditions => {:key => list_name.to_s, :key_type => LIST})
|
98
102
|
if last
|
data/lib/resque_extension.rb
CHANGED
@@ -118,6 +118,22 @@ describe 'RedisImpersonator' do
|
|
118
118
|
impersonator.lrange('some_queue', 0, 1).first.should == 'one'
|
119
119
|
impersonator.lrange('some_queue', 2, 3).first.should == 'three'
|
120
120
|
end
|
121
|
+
|
122
|
+
it 'should get all results if you pass -1 to lrange' do
|
123
|
+
impersonator.rpush('some_queue', 'one')
|
124
|
+
impersonator.rpush('some_queue', 'two')
|
125
|
+
impersonator.rpush('some_queue', 'three')
|
126
|
+
impersonator.lrange('some_queue', 0, -1).should include('one', 'two', 'three')
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should remove items from queue' do
|
130
|
+
impersonator.rpush('some_queue', 'one')
|
131
|
+
impersonator.rpush('some_queue', 'two')
|
132
|
+
impersonator.rpush('some_queue', 'two')
|
133
|
+
impersonator.lrem('some_queue', 0, 'two').should == 2
|
134
|
+
impersonator.lrange('some_queue', 0, -1).should include('one')
|
135
|
+
end
|
136
|
+
|
121
137
|
end
|
122
138
|
|
123
139
|
it 'should increment a value' do
|
data/swagger.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{swagger}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mdeiters"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-22}
|
13
13
|
s.description = %q{Duck punch Resque to use active record for backround jobs instead of redis}
|
14
14
|
s.email = %q{mdeiters@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
- 1
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 1.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- mdeiters
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-22 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|