sidekiq-dynamic-queues 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,131 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require 'spec_helper'
4
+ require 'rack'
5
+ require 'rack/test'
6
+ require 'sidekiq-dynamic-queues-server'
7
+
8
+ Sinatra::Base.set :environment, :test
9
+
10
+ describe "Dynamic Queues pages" do
11
+ include Rack::Test::Methods
12
+ include Sidekiq::DynamicQueues::Attributes
13
+
14
+ def app
15
+ @app ||= Sidekiq::Web.new
16
+ end
17
+
18
+ before(:each) do
19
+ Sidekiq.redis {|r| r.flushall }
20
+ end
21
+
22
+ context "existence in application" do
23
+
24
+ it "should respond to it's url" do
25
+ get "/dynamicqueue"
26
+ last_response.should be_ok
27
+ end
28
+
29
+ it "should display its tab" do
30
+ get "/"
31
+ last_response.body.should include '<a href="/dynamicqueue">DynamicQueues</a>'
32
+ end
33
+
34
+ end
35
+
36
+ context "show dynamic queues table" do
37
+
38
+ it "should shows default queue when nothing set" do
39
+ get "/dynamicqueue"
40
+
41
+ last_response.body.should include 'default'
42
+ end
43
+
44
+ it "should shows names of queues" do
45
+ set_dynamic_queue("key_one", ["foo"])
46
+ set_dynamic_queue("key_two", ["bar"])
47
+
48
+ get "/dynamicqueue"
49
+
50
+ last_response.body.should include 'key_one'
51
+ last_response.body.should include 'key_two'
52
+ end
53
+
54
+ it "should shows values of queues" do
55
+ set_dynamic_queue("key_one", ["foo"])
56
+ set_dynamic_queue("key_two", ["bar", "baz"])
57
+
58
+ get "/dynamicqueue"
59
+
60
+ last_response.body.should include 'foo'
61
+ last_response.body.should include 'bar, baz'
62
+ end
63
+
64
+ end
65
+
66
+ context "remove queue link" do
67
+
68
+ it "should show remove link for queue" do
69
+ set_dynamic_queue("key_one", ["foo"])
70
+
71
+ get "/dynamicqueue"
72
+
73
+ last_response.body.should match /<a .*href=['"]#remove['"].*>/
74
+ end
75
+
76
+ it "should show add link" do
77
+ get "/dynamicqueue"
78
+
79
+ last_response.body.should match /<a .*href=['"]#add['"].*>/
80
+ end
81
+
82
+ end
83
+
84
+ context "form to edit queues" do
85
+
86
+ it "should have form to edit queues" do
87
+ get "/dynamicqueue"
88
+
89
+ last_response.body.should match /<form action="\/dynamicqueue"/
90
+ end
91
+
92
+ it "should show input fields" do
93
+ set_dynamic_queue("key_one", ["foo"])
94
+ set_dynamic_queue("key_two", ["bar", "baz"])
95
+ get "/dynamicqueue"
96
+
97
+ last_response.body.should match /<input id="input-0-name" name="queues\[\]\[name\]" type="text" value="key_one"/
98
+ last_response.body.should match /<input id="input-0-value" name="queues\[\]\[value\]" type="text" value="foo"/
99
+ last_response.body.should match /<input id="input-1-name" name="queues\[\]\[name\]" type="text" value="key_two"/
100
+ last_response.body.should match /<input id="input-1-value" name="queues\[\]\[value\]" type="text" value="bar, baz"/
101
+ end
102
+
103
+ it "should delete queues on empty queue submit" do
104
+ set_dynamic_queue("key_two", ["bar", "baz"])
105
+ post "/dynamicqueue", {'queues' => [{'name' => "key_two", "value" => ""}]}
106
+
107
+ last_response.should be_redirect
108
+ last_response['Location'].should match /dynamicqueue/
109
+ get_dynamic_queue("key_two", []).should be_empty
110
+ end
111
+
112
+ it "should create queues" do
113
+ post "/dynamicqueue", {'queues' => [{'name' => "key_two", "value" => " foo, bar ,baz "}]}
114
+
115
+ last_response.should be_redirect
116
+ last_response['Location'].should match /dynamicqueue/
117
+ get_dynamic_queue("key_two").should == %w{foo bar baz}
118
+ end
119
+
120
+ it "should update queues" do
121
+ set_dynamic_queue("key_two", ["bar", "baz"])
122
+ post "/dynamicqueue", {'queues' => [{'name' => "key_two", "value" => "foo,bar,baz"}]}
123
+
124
+ last_response.should be_redirect
125
+ last_response['Location'].should match /dynamicqueue/
126
+ get_dynamic_queue("key_two").should == %w{foo bar baz}
127
+ end
128
+
129
+ end
130
+
131
+ end
@@ -0,0 +1,93 @@
1
+ require 'rspec'
2
+ require 'sidekiq-dynamic-queues'
3
+
4
+ # No need to start redis when running in Travis
5
+ unless ENV['CI']
6
+
7
+ begin
8
+ Sidekiq.redis {|r| r.info }
9
+ rescue Errno::ECONNREFUSED
10
+ spec_dir = File.dirname(File.expand_path(__FILE__))
11
+ REDIS_CMD = "redis-server #{spec_dir}/redis-test.conf"
12
+
13
+ puts "Starting redis for testing at localhost..."
14
+ puts `cd #{spec_dir}; #{REDIS_CMD}`
15
+
16
+ # Schedule the redis server for shutdown when tests are all finished.
17
+ at_exit do
18
+ puts 'Stopping redis'
19
+ pid = File.read("#{spec_dir}/redis.pid").to_i rescue nil
20
+ system ("kill -9 #{pid}") if pid.to_i != 0
21
+ File.delete("#{spec_dir}/redis.pid") rescue nil
22
+ File.delete("#{spec_dir}/redis-server.log") rescue nil
23
+ File.delete("#{spec_dir}/dump.rdb") rescue nil
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ def dump_redis
30
+ result = {}
31
+ Sidekiq.redis do |redis|
32
+ result = {}
33
+ redis.keys("*").each do |key|
34
+ type = redis.type(key)
35
+ result["#{key} (#{type})"] = case type
36
+ when 'string' then redis.get(key)
37
+ when 'list' then redis.lrange(key, 0, -1)
38
+ when 'zset' then redis.zrange(key, 0, -1, :with_scores => true)
39
+ when 'set' then redis.smembers(key)
40
+ when 'hash' then redis.hgetall(key)
41
+ else type
42
+ end
43
+ end
44
+ end
45
+ return result
46
+ end
47
+
48
+ require 'sidekiq'
49
+ require 'celluloid'
50
+ require 'sidekiq/cli'
51
+ require 'sidekiq/manager'
52
+
53
+ Sidekiq.configure_client do |config|
54
+ config.redis = { :namespace => 'sidekiq',
55
+ :size => 1,
56
+ :url => 'redis://localhost:6379/1' }
57
+ end
58
+
59
+ Sidekiq.configure_server do |config|
60
+ config.redis = { :namespace => 'sidekiq',
61
+ :url => 'redis://localhost:6379/1' }
62
+ end
63
+
64
+ Celluloid.logger = nil
65
+ Sidekiq.logger = nil
66
+ #Celluloid.logger = Sidekiq.logger
67
+
68
+ def enqueue_on(queue, job_class, *job_args)
69
+ job_class.client_push('class' => job_class, 'args' => job_args, 'queue' => queue)
70
+ end
71
+
72
+ def run_queues(*queues)
73
+ Sidekiq::Fetcher.instance_eval { @done = false }
74
+ manager = Sidekiq::Manager.new({:queues=>queues, :concurrency=>1, :timeout=>1})
75
+
76
+ manager.when_done do
77
+ manager.async.stop(:shutdown => true, :timeout => 0)
78
+ end
79
+ manager.async.start
80
+
81
+ manager.wait(:shutdown)
82
+ end
83
+
84
+
85
+ class SomeJob
86
+ include Sidekiq::Worker
87
+
88
+ class_attribute :result
89
+
90
+ def perform(*args)
91
+ self.class.result = args
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sidekiq-dynamic-queues
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matt Conway
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sidekiq
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.9'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.9'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.5'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.5'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sinatra
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: slim
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rack-test
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.5.4
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.5.4
110
+ description: A sidekiq plugin for specifying the queues a worker pulls from with wildcards,
111
+ negations, or dynamic look up from redis
112
+ email:
113
+ - matt@conwaysplace.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .travis.yml
120
+ - CHANGELOG
121
+ - Gemfile
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - config.ru
126
+ - init.rb
127
+ - lib/sidekiq-dynamic-queues-server.rb
128
+ - lib/sidekiq-dynamic-queues.rb
129
+ - lib/sidekiq/dynamic_queues/attributes.rb
130
+ - lib/sidekiq/dynamic_queues/fetch.rb
131
+ - lib/sidekiq/dynamic_queues/server.rb
132
+ - lib/sidekiq/dynamic_queues/server/views/dynamicqueue.slim
133
+ - lib/sidekiq/dynamic_queues/version.rb
134
+ - sidekiq-dynamic-queues.gemspec
135
+ - spec/queues_spec.rb
136
+ - spec/redis-test.conf
137
+ - spec/server_spec.rb
138
+ - spec/spec_helper.rb
139
+ homepage: ''
140
+ licenses: []
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project: sidekiq-dynamic-queues
159
+ rubygems_version: 1.8.25
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: A sidekiq plugin for specifying the queues a worker pulls from with wildcards,
163
+ negations, or dynamic look up from redis
164
+ test_files:
165
+ - spec/queues_spec.rb
166
+ - spec/redis-test.conf
167
+ - spec/server_spec.rb
168
+ - spec/spec_helper.rb
169
+ has_rdoc: