redis_monitor 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.travis.yml +1 -1
  4. data/README.md +7 -9
  5. data/Rakefile +4 -0
  6. data/lib/engine/app/controllers/content_controller.rb +1 -1
  7. data/lib/engine/app/controllers/notifications_controller.rb +19 -0
  8. data/lib/engine/app/controllers/tasks_controller.rb +47 -0
  9. data/lib/engine/app/helpers/application_helper.rb +13 -3
  10. data/lib/engine/app/lib/commands/retrieve_key.rb +5 -0
  11. data/lib/engine/app/lib/commands/{search_key.rb → search_keys.rb} +1 -1
  12. data/lib/engine/app/lib/jobs/background_task_job.rb +42 -0
  13. data/lib/engine/app/models/notification.rb +7 -0
  14. data/lib/engine/app/models/task.rb +34 -0
  15. data/lib/engine/app/models/watch_key_task.rb +22 -0
  16. data/lib/engine/app/models/watch_query_task.rb +24 -0
  17. data/lib/engine/app/views/content/_search_form.haml +2 -2
  18. data/lib/engine/app/views/layouts/application.haml +1 -0
  19. data/lib/engine/app/views/notifications/_notification.haml +9 -0
  20. data/lib/engine/app/views/notifications/index.haml +14 -0
  21. data/lib/engine/app/views/tasks/_form.haml +32 -0
  22. data/lib/engine/app/views/tasks/_task.haml +14 -0
  23. data/lib/engine/app/views/tasks/edit.haml +3 -0
  24. data/lib/engine/app/views/tasks/index.haml +21 -0
  25. data/lib/engine/app/views/tasks/new.haml +3 -0
  26. data/lib/engine/bin/delayed_job +5 -0
  27. data/lib/engine/config/database.yml +2 -2
  28. data/lib/engine/config/initializers/delayed_job.rb +3 -0
  29. data/lib/engine/config/routes.rb +3 -0
  30. data/lib/engine/db/migrate/20140112162911_create_tasks.rb +15 -0
  31. data/lib/engine/db/migrate/20140118155310_create_delayed_jobs.rb +22 -0
  32. data/lib/engine/db/migrate/20140118183403_create_notifications.rb +10 -0
  33. data/lib/engine/db/schema.rb +51 -0
  34. data/lib/engine/public/javascripts/jquery_ujs.js +394 -0
  35. data/lib/engine/public/stylesheets/custom.css +4 -0
  36. data/lib/engine/spec/controllers/content_controller_spec.rb +1 -1
  37. data/lib/engine/spec/controllers/notifications_controller_spec.rb +39 -0
  38. data/lib/engine/spec/controllers/tasks_controller_spec.rb +109 -0
  39. data/lib/engine/spec/lib/commands/retrieve_key_spec.rb +15 -0
  40. data/lib/engine/spec/lib/commands/search_key_spec.rb +2 -2
  41. data/lib/engine/spec/lib/jobs/background_task_job_spec.rb +55 -0
  42. data/lib/engine/spec/models/notification_spec.rb +9 -0
  43. data/lib/engine/spec/models/task_spec.rb +23 -0
  44. data/lib/engine/spec/models/watch_key_task_spec.rb +13 -0
  45. data/lib/engine/spec/models/watch_query_task_spec.rb +13 -0
  46. data/lib/redis_monitor.rb +7 -1
  47. data/lib/version.rb +1 -1
  48. data/redis_monitor.gemspec +2 -0
  49. metadata +61 -10
  50. data/lib/engine/test/controllers/.keep +0 -0
  51. data/lib/engine/test/fixtures/.keep +0 -0
  52. data/lib/engine/test/helpers/.keep +0 -0
  53. data/lib/engine/test/integration/.keep +0 -0
  54. data/lib/engine/test/mailers/.keep +0 -0
  55. data/lib/engine/test/models/.keep +0 -0
  56. data/lib/engine/test/test_helper.rb +0 -15
@@ -5,4 +5,8 @@ body {
5
5
  .message_centered {
6
6
  text-align: center;
7
7
  padding-top: 20%;
8
+ }
9
+
10
+ h1, h2 {
11
+ margin-top: 0px;
8
12
  }
@@ -11,7 +11,7 @@ describe ContentController do
11
11
 
12
12
  describe 'search action' do
13
13
  it 'should search on backend' do
14
- SearchKey.any_instance.should_receive(:result){ [] }
14
+ SearchKeys.any_instance.should_receive(:result){ [] }
15
15
  get :search
16
16
  end
17
17
  end
@@ -0,0 +1,39 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe NotificationsController do
4
+ before :each do
5
+ controller.stub(:load_section)
6
+ end
7
+
8
+ describe 'index action' do
9
+ it 'should assigns notifications' do
10
+ get :index
11
+ assigns[:notifications].should_not be_nil
12
+ end
13
+
14
+ it 'should render template index' do
15
+ get :index
16
+ controller.should render_template('index')
17
+ end
18
+ end
19
+
20
+ describe 'destroy action' do
21
+ let(:id){ 33}
22
+ let(:notification){ double() }
23
+
24
+ before :each do
25
+ Notification.stub(:find){ notification }
26
+ notification.stub(:destroy)
27
+ end
28
+
29
+ it 'should call destroy on the notification' do
30
+ notification.should_receive(:destroy)
31
+ delete :destroy, id: id
32
+ end
33
+
34
+ it 'should redirect to action index' do
35
+ delete :destroy, id: id
36
+ controller.should redirect_to(action: :index)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,109 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe TasksController do
4
+ let(:id){ 777 }
5
+ let(:task){ double() }
6
+ let(:task_params){ {name: 'task'} }
7
+
8
+ before :each do
9
+ controller.stub(:load_section)
10
+ controller.stub(:task_params){ task_params }
11
+ controller.stub(:reset_queue)
12
+ Task.stub(:find){ task }
13
+ end
14
+
15
+ describe 'index action' do
16
+ it 'should assigns tasks' do
17
+ get :index
18
+ assigns[:tasks].should_not be_nil
19
+ end
20
+
21
+ it 'should render template index' do
22
+ get :index
23
+ controller.should render_template('index')
24
+ end
25
+ end
26
+
27
+ describe 'new action' do
28
+ it 'should assigns task' do
29
+ get :new
30
+ assigns[:task].should_not be_nil
31
+ end
32
+
33
+ it 'should render template new' do
34
+ get :new
35
+ controller.should render_template('new')
36
+ end
37
+ end
38
+
39
+ describe 'edit action' do
40
+ it 'should assigns task' do
41
+ get :edit, id: id
42
+ assigns[:task].should_not be_nil
43
+ end
44
+
45
+ it 'should render template edit' do
46
+ get :edit, id: id
47
+ controller.should render_template('edit')
48
+ end
49
+ end
50
+
51
+ describe 'create action' do
52
+ it 'should assigns task' do
53
+ post :create
54
+ assigns[:task].should_not be_nil
55
+ end
56
+
57
+ it 'should save task' do
58
+ post :create
59
+ assigns[:task].should be_persisted
60
+ end
61
+
62
+ it 'should redirect to action index' do
63
+ post :create
64
+ controller.should redirect_to(action: :index)
65
+ end
66
+ end
67
+
68
+ describe 'update action' do
69
+ before :each do
70
+ task.stub(:update_attributes)
71
+ end
72
+
73
+ it 'should assigns task' do
74
+ put :update, id: id
75
+ assigns[:task].should_not be_nil
76
+ end
77
+
78
+ it 'should update task' do
79
+ task.should_receive(:update_attributes)
80
+ put :update, id: id
81
+ end
82
+
83
+ it 'should redirect to action index' do
84
+ put :update, id: id
85
+ controller.should redirect_to(action: :index)
86
+ end
87
+ end
88
+
89
+ describe 'destroy action' do
90
+ before :each do
91
+ task.stub(:destroy)
92
+ end
93
+
94
+ it 'should assigns task' do
95
+ delete :destroy, id: id
96
+ assigns[:task].should_not be_nil
97
+ end
98
+
99
+ it 'should call destroy on the task' do
100
+ task.should_receive(:destroy)
101
+ delete :destroy, id: id
102
+ end
103
+
104
+ it 'should redirect to action index' do
105
+ delete :destroy, id: id
106
+ controller.should redirect_to(action: :index)
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe RetrieveKey do
4
+ let(:backend){ double() }
5
+ let(:key){ 'key' }
6
+ let(:value){ 'value' }
7
+ let(:command){ RetrieveKey.new(backend, key) }
8
+
9
+ describe 'result' do
10
+ it 'should return the value associated to the key' do
11
+ backend.stub(:get){ value }
12
+ command.result.should == value
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,9 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
- describe SearchKey do
3
+ describe SearchKeys do
4
4
  let(:backend){ double() }
5
5
  let(:key){ 'key' }
6
- let(:command){ SearchKey.new(backend, key) }
6
+ let(:command){ SearchKeys.new(backend, key) }
7
7
  let(:keys_found){ ['k1', 'k2', 'k3'] }
8
8
 
9
9
  describe 'result' do
@@ -0,0 +1,55 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe BackgroundTaskJob do
4
+ let(:task){ double(id: 1, every: 60) }
5
+ let(:job){ BackgroundTaskJob.new(task) }
6
+
7
+ it 'should respond to perform' do
8
+ job.should respond_to(:perform)
9
+ end
10
+
11
+ describe 'queue_name' do
12
+ it 'should include task id' do
13
+ job.queue_name.should include(task.id.to_s)
14
+ end
15
+ end
16
+
17
+ describe 'add_to_queue' do
18
+ it 'should enqueue job if task is active' do
19
+ task.stub(:active?){ true }
20
+ Delayed::Job.should_receive(:enqueue)
21
+ job.add_to_queue
22
+ end
23
+
24
+ it 'should not enqueue job if task is not active' do
25
+ task.stub(:active?){ false }
26
+ Delayed::Job.should_not_receive(:enqueue)
27
+ job.add_to_queue
28
+ end
29
+ end
30
+
31
+ describe 'reset_queue' do
32
+ before :each do
33
+ job.stub(:clear_queue)
34
+ job.stub(:add_to_queue)
35
+ end
36
+
37
+ it 'should call clear_queue' do
38
+ job.should_receive(:clear_queue)
39
+ job.reset_queue
40
+ end
41
+
42
+ it 'should call add_to_queue' do
43
+ job.should_receive(:add_to_queue)
44
+ job.reset_queue
45
+ end
46
+ end
47
+
48
+ describe 'after' do
49
+ it 'should call add_to_queue' do
50
+ job.stub(:refresh_data){ task }
51
+ job.should_receive(:add_to_queue)
52
+ job.after(job)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Notification do
4
+ let(:notification){ Notification.new }
5
+
6
+ it 'should respond to when' do
7
+ notification.should respond_to(:when)
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Task do
4
+ let(:task){ Task.new }
5
+
6
+ it 'should respond to active?' do
7
+ task.should respond_to(:active?)
8
+ end
9
+
10
+ it 'should respond to reset_queue' do
11
+ task.should respond_to(:reset_queue)
12
+ end
13
+
14
+ it 'should respond to backend' do
15
+ task.should respond_to(:backend)
16
+ end
17
+
18
+ it 'should use default values after initialization' do
19
+ Task.new.every.should == Task::DEFAULT_INTERVAL
20
+ Task.new.database.should == Task::DEFAULT_DATABASE
21
+ end
22
+
23
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe WatchKeyTask do
4
+ let(:task){ WatchKeyTask.new }
5
+
6
+ it 'should respond to type_name' do
7
+ task.should respond_to(:type_name)
8
+ end
9
+
10
+ it 'should respond to perform' do
11
+ task.should respond_to(:perform)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe WatchQueryTask do
4
+ let(:task){ WatchQueryTask.new }
5
+
6
+ it 'should respond to type_name' do
7
+ task.should respond_to(:type_name)
8
+ end
9
+
10
+ it 'should respond to perform' do
11
+ task.should respond_to(:perform)
12
+ end
13
+ end
data/lib/redis_monitor.rb CHANGED
@@ -10,10 +10,16 @@ module RedisMonitor
10
10
  ENV['REDIS_MONITOR_OPTS'] = Base64.encode64(Marshal.dump(args))
11
11
  end
12
12
 
13
+ def self.environment
14
+ 'production'
15
+ end
16
+
13
17
  def self.run
14
18
  args = parse_arguments
15
19
  store_arguments(args)
16
20
 
17
- system('lib/engine/bin/rails', 's', '-p', args[:http_port].to_s, '-e', 'production')
21
+ system('lib/engine/bin/rake', 'db:migrate', "RAILS_ENV=#{environment}")
22
+ system('lib/engine/bin/delayed_job', 'restart', "RAILS_ENV=#{environment}")
23
+ system('lib/engine/bin/rails', 's', '-p', args[:http_port].to_s, '-e', environment)
18
24
  end
19
25
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RedisMonitor
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3'
3
3
  end
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
33
33
  spec.add_runtime_dependency 'twitter-bootstrap-rails'
34
34
  spec.add_runtime_dependency 'will_paginate', '~> 3.0.5'
35
35
  spec.add_runtime_dependency 'will_paginate-bootstrap'
36
+ spec.add_runtime_dependency 'delayed_job_active_record'
37
+ spec.add_runtime_dependency 'daemons'
36
38
 
37
39
  spec.add_development_dependency 'bundler', '~> 1.3'
38
40
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Jimenez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-12 00:00:00.000000000 Z
11
+ date: 2014-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: delayed_job_active_record
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: daemons
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: bundler
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -204,7 +232,9 @@ files:
204
232
  - lib/engine/app/controllers/concerns/.keep
205
233
  - lib/engine/app/controllers/content_controller.rb
206
234
  - lib/engine/app/controllers/info_controller.rb
235
+ - lib/engine/app/controllers/notifications_controller.rb
207
236
  - lib/engine/app/controllers/performance_controller.rb
237
+ - lib/engine/app/controllers/tasks_controller.rb
208
238
  - lib/engine/app/helpers/application_helper.rb
209
239
  - lib/engine/app/helpers/database_helper.rb
210
240
  - lib/engine/app/helpers/pagination_helper.rb
@@ -214,20 +244,34 @@ files:
214
244
  - lib/engine/app/lib/commands/database_list.rb
215
245
  - lib/engine/app/lib/commands/performance_stats.rb
216
246
  - lib/engine/app/lib/commands/remove_key.rb
217
- - lib/engine/app/lib/commands/search_key.rb
247
+ - lib/engine/app/lib/commands/retrieve_key.rb
248
+ - lib/engine/app/lib/commands/search_keys.rb
249
+ - lib/engine/app/lib/jobs/background_task_job.rb
218
250
  - lib/engine/app/lib/security/authentication.rb
219
251
  - lib/engine/app/lib/security/authorization.rb
220
252
  - lib/engine/app/mailers/.keep
221
253
  - lib/engine/app/models/.keep
222
254
  - lib/engine/app/models/concerns/.keep
255
+ - lib/engine/app/models/notification.rb
256
+ - lib/engine/app/models/task.rb
257
+ - lib/engine/app/models/watch_key_task.rb
258
+ - lib/engine/app/models/watch_query_task.rb
223
259
  - lib/engine/app/views/content/_search_form.haml
224
260
  - lib/engine/app/views/content/index.haml
225
261
  - lib/engine/app/views/content/search.haml
226
262
  - lib/engine/app/views/info/index.haml
227
263
  - lib/engine/app/views/layouts/application.haml
264
+ - lib/engine/app/views/notifications/_notification.haml
265
+ - lib/engine/app/views/notifications/index.haml
228
266
  - lib/engine/app/views/performance/check.haml
229
267
  - lib/engine/app/views/performance/index.haml
268
+ - lib/engine/app/views/tasks/_form.haml
269
+ - lib/engine/app/views/tasks/_task.haml
270
+ - lib/engine/app/views/tasks/edit.haml
271
+ - lib/engine/app/views/tasks/index.haml
272
+ - lib/engine/app/views/tasks/new.haml
230
273
  - lib/engine/bin/bundle
274
+ - lib/engine/bin/delayed_job
231
275
  - lib/engine/bin/rails
232
276
  - lib/engine/bin/rake
233
277
  - lib/engine/config.ru
@@ -240,6 +284,7 @@ files:
240
284
  - lib/engine/config/environments/test.rb
241
285
  - lib/engine/config/initializers/backtrace_silencers.rb
242
286
  - lib/engine/config/initializers/configuration.rb
287
+ - lib/engine/config/initializers/delayed_job.rb
243
288
  - lib/engine/config/initializers/filter_parameter_logging.rb
244
289
  - lib/engine/config/initializers/haml.rb
245
290
  - lib/engine/config/initializers/inflections.rb
@@ -251,6 +296,10 @@ files:
251
296
  - lib/engine/config/locales/en.bootstrap.yml
252
297
  - lib/engine/config/locales/en.yml
253
298
  - lib/engine/config/routes.rb
299
+ - lib/engine/db/migrate/20140112162911_create_tasks.rb
300
+ - lib/engine/db/migrate/20140118155310_create_delayed_jobs.rb
301
+ - lib/engine/db/migrate/20140118183403_create_notifications.rb
302
+ - lib/engine/db/schema.rb
254
303
  - lib/engine/db/seeds.rb
255
304
  - lib/engine/lib/assets/.keep
256
305
  - lib/engine/lib/tasks/.keep
@@ -263,29 +312,31 @@ files:
263
312
  - lib/engine/public/javascripts/bootstrap-select.min.js
264
313
  - lib/engine/public/javascripts/bootstrap.min.js
265
314
  - lib/engine/public/javascripts/jquery-2.0.3.min.js
315
+ - lib/engine/public/javascripts/jquery_ujs.js
266
316
  - lib/engine/public/robots.txt
267
317
  - lib/engine/public/stylesheets/bootstrap-select.min.css
268
318
  - lib/engine/public/stylesheets/bootstrap.min.css
269
319
  - lib/engine/public/stylesheets/custom.css
270
320
  - lib/engine/spec/controllers/content_controller_spec.rb
271
321
  - lib/engine/spec/controllers/info_controller_spec.rb
322
+ - lib/engine/spec/controllers/notifications_controller_spec.rb
272
323
  - lib/engine/spec/controllers/performance_controller_spec.rb
324
+ - lib/engine/spec/controllers/tasks_controller_spec.rb
273
325
  - lib/engine/spec/lib/backend_spec.rb
274
326
  - lib/engine/spec/lib/commands/change_database_spec.rb
275
327
  - lib/engine/spec/lib/commands/database_list_spec.rb
276
328
  - lib/engine/spec/lib/commands/performance_stats_spec.rb
277
329
  - lib/engine/spec/lib/commands/remove_key_spec.rb
330
+ - lib/engine/spec/lib/commands/retrieve_key_spec.rb
278
331
  - lib/engine/spec/lib/commands/search_key_spec.rb
332
+ - lib/engine/spec/lib/jobs/background_task_job_spec.rb
279
333
  - lib/engine/spec/lib/security/authentication_spec.rb
280
334
  - lib/engine/spec/lib/security/authorization_spec.rb
335
+ - lib/engine/spec/models/notification_spec.rb
336
+ - lib/engine/spec/models/task_spec.rb
337
+ - lib/engine/spec/models/watch_key_task_spec.rb
338
+ - lib/engine/spec/models/watch_query_task_spec.rb
281
339
  - lib/engine/spec/spec_helper.rb
282
- - lib/engine/test/controllers/.keep
283
- - lib/engine/test/fixtures/.keep
284
- - lib/engine/test/helpers/.keep
285
- - lib/engine/test/integration/.keep
286
- - lib/engine/test/mailers/.keep
287
- - lib/engine/test/models/.keep
288
- - lib/engine/test/test_helper.rb
289
340
  - lib/engine/vendor/assets/javascripts/.keep
290
341
  - lib/engine/vendor/assets/stylesheets/.keep
291
342
  - lib/redis_monitor.rb