gorgon 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +8 -8
  2. data/.ruby-version +1 -0
  3. data/Gemfile.lock +5 -5
  4. data/README.md +2 -0
  5. data/lib/gorgon/g_logger.rb +3 -1
  6. data/lib/gorgon/originator.rb +8 -9
  7. data/lib/gorgon/originator_protocol.rb +2 -2
  8. data/lib/gorgon/shutdown_manager.rb +32 -0
  9. data/lib/gorgon/version.rb +1 -1
  10. data/spec/acceptance/run_tests_spec.rb +9 -0
  11. data/spec/acceptance_spec_helper.rb +7 -0
  12. data/spec/listener_spec.rb +1 -1
  13. data/spec/originator_spec.rb +7 -15
  14. data/spec/shutdown_manager_spec.rb +49 -0
  15. data/spec/support/mock_app/.gitignore +15 -0
  16. data/spec/support/mock_app/Gemfile +39 -0
  17. data/spec/support/mock_app/Gemfile.lock +135 -0
  18. data/spec/support/mock_app/README.rdoc +261 -0
  19. data/spec/support/mock_app/Rakefile +7 -0
  20. data/spec/support/mock_app/app/assets/images/rails.png +0 -0
  21. data/spec/support/mock_app/app/assets/javascripts/application.js +15 -0
  22. data/spec/support/mock_app/app/assets/stylesheets/application.css +13 -0
  23. data/spec/support/mock_app/app/controllers/application_controller.rb +3 -0
  24. data/spec/support/mock_app/app/helpers/application_helper.rb +2 -0
  25. data/spec/support/mock_app/app/mailers/.gitkeep +0 -0
  26. data/spec/support/mock_app/app/models/.gitkeep +0 -0
  27. data/spec/support/mock_app/app/views/layouts/application.html.erb +14 -0
  28. data/spec/support/mock_app/config.ru +4 -0
  29. data/spec/support/mock_app/config/application.rb +62 -0
  30. data/spec/support/mock_app/config/boot.rb +6 -0
  31. data/spec/support/mock_app/config/database.yml +25 -0
  32. data/spec/support/mock_app/config/environment.rb +5 -0
  33. data/spec/support/mock_app/config/environments/development.rb +37 -0
  34. data/spec/support/mock_app/config/environments/production.rb +67 -0
  35. data/spec/support/mock_app/config/environments/test.rb +37 -0
  36. data/spec/support/mock_app/config/initializers/backtrace_silencers.rb +7 -0
  37. data/spec/support/mock_app/config/initializers/inflections.rb +15 -0
  38. data/spec/support/mock_app/config/initializers/mime_types.rb +5 -0
  39. data/spec/support/mock_app/config/initializers/secret_token.rb +7 -0
  40. data/spec/support/mock_app/config/initializers/session_store.rb +8 -0
  41. data/spec/support/mock_app/config/initializers/wrap_parameters.rb +14 -0
  42. data/spec/support/mock_app/config/locales/en.yml +5 -0
  43. data/spec/support/mock_app/config/routes.rb +58 -0
  44. data/spec/support/mock_app/db/seeds.rb +7 -0
  45. data/spec/support/mock_app/doc/README_FOR_APP +2 -0
  46. data/spec/support/mock_app/lib/assets/.gitkeep +0 -0
  47. data/spec/support/mock_app/lib/tasks/.gitkeep +0 -0
  48. data/spec/support/mock_app/log/.gitkeep +0 -0
  49. data/spec/support/mock_app/public/404.html +26 -0
  50. data/spec/support/mock_app/public/422.html +26 -0
  51. data/spec/support/mock_app/public/500.html +25 -0
  52. data/spec/support/mock_app/public/favicon.ico +0 -0
  53. data/spec/support/mock_app/public/index.html +241 -0
  54. data/spec/support/mock_app/public/robots.txt +5 -0
  55. data/spec/support/mock_app/script/rails +6 -0
  56. data/spec/support/mock_app/test/fixtures/.gitkeep +0 -0
  57. data/spec/support/mock_app/test/functional/.gitkeep +0 -0
  58. data/spec/support/mock_app/test/integration/.gitkeep +0 -0
  59. data/spec/support/mock_app/test/performance/browsing_test.rb +12 -0
  60. data/spec/support/mock_app/test/test_helper.rb +13 -0
  61. data/spec/support/mock_app/test/unit/.gitkeep +0 -0
  62. data/spec/support/mock_app/test/unit/passing_test.rb +7 -0
  63. data/spec/support/mock_app/vendor/assets/javascripts/.gitkeep +0 -0
  64. data/spec/support/mock_app/vendor/assets/stylesheets/.gitkeep +0 -0
  65. data/spec/support/mock_app/vendor/plugins/.gitkeep +0 -0
  66. data/spec/support/originator_handler.rb +8 -0
  67. metadata +59 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
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15
+ NjQ4ZWRkYmY2MTYxYWE3OWNkNzAxMDIzYTY4MThmZDQ0NDZjZmQ=
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.3-p484
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gorgon (0.6.3)
4
+ gorgon (0.6.4)
5
5
  amqp (~> 1.1.0)
6
6
  awesome_print
7
7
  colorize (~> 0.5.8)
@@ -13,15 +13,15 @@ PATH
13
13
  GEM
14
14
  remote: http://rubygems.org/
15
15
  specs:
16
- amq-protocol (1.9.0)
17
- amqp (1.1.5)
18
- amq-protocol (>= 1.9.0)
16
+ amq-protocol (1.9.2)
17
+ amqp (1.1.8)
18
+ amq-protocol (>= 1.9.2)
19
19
  eventmachine
20
20
  awesome_print (1.2.0)
21
21
  colorize (0.5.8)
22
22
  diff-lcs (1.1.3)
23
23
  eventmachine (1.0.3)
24
- open4 (1.3.0)
24
+ open4 (1.3.3)
25
25
  rake (0.9.2.2)
26
26
  rspec (2.11.0)
27
27
  rspec-core (~> 2.11.0)
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  Gorgon
2
2
  =====================
3
3
 
4
+ [![Code Climate](https://codeclimate.com/github/Fitzsimmons/Gorgon.png)](https://codeclimate.com/github/Fitzsimmons/Gorgon)
5
+
4
6
  About
5
7
  ---------------------
6
8
 
@@ -1,13 +1,15 @@
1
1
  require "logger"
2
2
 
3
3
  module GLogger
4
+ SIZE_1_MB = 1048576
5
+
4
6
  def initialize_logger log_file
5
7
  return unless log_file
6
8
  @logger =
7
9
  if log_file == "-"
8
10
  Logger.new($stdout)
9
11
  else
10
- Logger.new(log_file)
12
+ Logger.new(log_file, 1, SIZE_1_MB)
11
13
  end
12
14
  @logger.datetime_format = "%Y-%m-%d %H:%M:%S "
13
15
  end
@@ -5,6 +5,7 @@ require 'gorgon/progress_bar_view'
5
5
  require 'gorgon/originator_logger'
6
6
  require 'gorgon/failures_printer'
7
7
  require 'gorgon/rsync_daemon'
8
+ require 'gorgon/shutdown_manager.rb'
8
9
 
9
10
  require 'awesome_print'
10
11
  require 'etc'
@@ -31,24 +32,22 @@ class Originator
31
32
  puts $!.backtrace.join("\n")
32
33
  puts "----------------------------------"
33
34
  puts "Now attempting to cancel the job."
34
- @logger.log_error "Unhandled Exception!"
35
+ @logger.log_error "Unhandled Exception!" if @logger
35
36
  cancel_job
36
37
  end
37
38
  end
38
39
 
40
+ def cancel_job
41
+ ShutdownManager.new(protocol: @protocol,
42
+ job_state: @job_state,
43
+ rsync_daemon: @rsync_daemon).cancel_job
44
+ end
45
+
39
46
  def ctrl_c
40
47
  puts "\nCtrl-C received! Just wait a moment while I clean up..."
41
48
  cancel_job
42
49
  end
43
50
 
44
- def cancel_job
45
- @protocol.cancel_job
46
- @job_state.cancel
47
-
48
- @protocol.disconnect
49
- @rsync_daemon.stop
50
- end
51
-
52
51
  def publish
53
52
  @logger = OriginatorLogger.new configuration[:originator_log_file]
54
53
 
@@ -45,13 +45,13 @@ class OriginatorProtocol
45
45
 
46
46
  def cancel_job
47
47
  @file_queue.purge if @file_queue
48
- @channel.fanout("gorgon.worker_managers").publish(cancel_message)
48
+ @channel.fanout("gorgon.worker_managers").publish(cancel_message) if @channel
49
49
  @logger.log "Cancel Message sent"
50
50
  end
51
51
 
52
52
  def disconnect
53
53
  cleanup_queues_and_exchange
54
- @connection.disconnect
54
+ @connection.disconnect if @connection
55
55
  end
56
56
 
57
57
  private
@@ -0,0 +1,32 @@
1
+ class ShutdownManager
2
+
3
+ def initialize(args)
4
+ @protocol = args.fetch(:protocol)
5
+ @job_state = args.fetch(:job_state)
6
+ @rsync_daemon = args.fetch(:rsync_daemon)
7
+ end
8
+
9
+ def cancel_job
10
+ @protocol.cancel_job if @protocol
11
+ ensure
12
+ cancel_job_state
13
+ end
14
+
15
+ private
16
+
17
+ def cancel_job_state
18
+ @job_state.cancel if @job_state
19
+ ensure
20
+ disconnect_protocol
21
+ end
22
+
23
+ def disconnect_protocol
24
+ @protocol.disconnect if @protocol
25
+ ensure
26
+ stop_rsync_daemon
27
+ end
28
+
29
+ def stop_rsync_daemon
30
+ @rsync_daemon.stop if @rsync_daemon
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Gorgon
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'acceptance_spec_helper'
2
+
3
+ describe 'Gorgon' do
4
+ it 'run tests' do
5
+ pending 'Use a different observer of job_state to check expectations'
6
+
7
+ run_originator
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift File.expand_path("../../lib", __FILE__)
2
+ require "gorgon"
3
+ require File.expand_path("../support/originator_handler", __FILE__)
4
+
5
+ RSpec.configure do |config|
6
+ config.include OriginatorHandler
7
+ end
@@ -38,7 +38,7 @@ describe Listener do
38
38
  end
39
39
 
40
40
  it "should use 'log_file' from the configuration as the log file" do
41
- Logger.should_receive(:new).with('listener.log')
41
+ Logger.should_receive(:new).with('listener.log', anything, anything)
42
42
  Listener.new
43
43
  end
44
44
 
@@ -60,22 +60,14 @@ describe Originator do
60
60
  stub_methods
61
61
  end
62
62
 
63
- it "call JobState#cancel" do
63
+ it 'tells ShutdownManager to cancel_job' do
64
+ shutdown_manager = double('ShutdownManager')
64
65
  JobState.stub!(:new).and_return job_state
65
- job_state.should_receive(:cancel)
66
- @originator.publish
67
- @originator.cancel_job
68
- end
69
-
70
- it "tells @protocol to cancel job and disconnect" do
71
- protocol.should_receive(:cancel_job)
72
- protocol.should_receive(:disconnect)
73
- @originator.publish
74
- @originator.cancel_job
75
- end
76
66
 
77
- it "stops the rsync daemon" do
78
- rsync_daemon.should_receive(:stop)
67
+ ShutdownManager.should_receive(:new).
68
+ with(hash_including(protocol: protocol, job_state: job_state, rsync_daemon: rsync_daemon)).
69
+ and_return(shutdown_manager)
70
+ shutdown_manager.should_receive(:cancel_job)
79
71
 
80
72
  @originator.publish
81
73
  @originator.cancel_job
@@ -121,7 +113,7 @@ describe Originator do
121
113
  end
122
114
 
123
115
  it "calls JobState#file_started if payload[:action] is 'start'" do
124
- payload = Yajl::Parser.new(:symbolize_keys => true).parse(start_payload)
116
+ Yajl::Parser.new(:symbolize_keys => true).parse(start_payload)
125
117
  job_state.should_receive(:file_started)
126
118
  @originator.handle_reply(start_payload)
127
119
  end
@@ -0,0 +1,49 @@
1
+ require 'gorgon/shutdown_manager'
2
+
3
+ describe ShutdownManager do
4
+ let(:protocol){ stub("Originator Protocol", :cancel_job => nil, :disconnect => nil)}
5
+
6
+ let(:job_state){ stub("JobState", cancel: nil)}
7
+ let(:rsync_daemon) { stub("Rsync Daemon", :stop => true)}
8
+
9
+ describe '#cancel_job' do
10
+ it "call JobState#cancel" do
11
+ job_state.should_receive(:cancel)
12
+
13
+ shutdown_manager(job_state: job_state).cancel_job
14
+ end
15
+
16
+ it "tells @protocol to cancel job and disconnect" do
17
+ protocol.should_receive(:cancel_job)
18
+ protocol.should_receive(:disconnect)
19
+
20
+ shutdown_manager(protocol: protocol).cancel_job
21
+ end
22
+
23
+ it "stops the rsync daemon" do
24
+ rsync_daemon.should_receive(:stop)
25
+
26
+ shutdown_manager(rsync_daemon: rsync_daemon).cancel_job
27
+ end
28
+
29
+ it 'finishes cancelling job even when some cancelling steps fail' do
30
+ protocol.should_receive(:cancel_job).and_raise StandardError
31
+ job_state.should_receive(:cancel).and_raise StandardError
32
+ protocol.should_receive(:disconnect).and_raise StandardError
33
+ rsync_daemon.should_receive(:stop).and_raise StandardError
34
+
35
+ expect {
36
+ shutdown_manager(protocol: protocol, job_state: job_state, rsync_daemon: rsync_daemon).cancel_job
37
+ }.to raise_error StandardError
38
+ end
39
+ end
40
+
41
+ def shutdown_manager(args)
42
+ defaults = {
43
+ protocol: protocol,
44
+ job_state: job_state,
45
+ rsync_daemon: rsync_daemon
46
+ }
47
+ ShutdownManager.new(defaults.merge(args))
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
@@ -0,0 +1,39 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '3.2.11'
4
+
5
+ # Bundle edge Rails instead:
6
+ # gem 'rails', :git => 'git://github.com/rails/rails.git'
7
+
8
+ gem 'sqlite3'
9
+
10
+
11
+ # Gems used only for assets and not required
12
+ # in production environments by default.
13
+ group :assets do
14
+ gem 'sass-rails', '~> 3.2.3'
15
+ gem 'coffee-rails', '~> 3.2.1'
16
+
17
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
18
+ # gem 'therubyracer', :platforms => :ruby
19
+
20
+ gem 'uglifier', '>= 1.0.3'
21
+ end
22
+
23
+ gem 'jquery-rails'
24
+ gem 'gorgon', path: '../../../'
25
+
26
+ # To use ActiveModel has_secure_password
27
+ # gem 'bcrypt-ruby', '~> 3.0.0'
28
+
29
+ # To use Jbuilder templates for JSON
30
+ # gem 'jbuilder'
31
+
32
+ # Use unicorn as the app server
33
+ # gem 'unicorn'
34
+
35
+ # Deploy with Capistrano
36
+ # gem 'capistrano'
37
+
38
+ # To use debugger
39
+ # gem 'debugger'
@@ -0,0 +1,135 @@
1
+ PATH
2
+ remote: ../../../
3
+ specs:
4
+ gorgon (0.7.0.pre)
5
+ amqp (~> 1.1.0)
6
+ awesome_print
7
+ colorize (~> 0.5.8)
8
+ open4 (~> 1.3.0)
9
+ ruby-progressbar (~> 1.0.1)
10
+ uuidtools (= 2.1.3)
11
+ yajl-ruby (= 1.1.0)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actionmailer (3.2.11)
17
+ actionpack (= 3.2.11)
18
+ mail (~> 2.4.4)
19
+ actionpack (3.2.11)
20
+ activemodel (= 3.2.11)
21
+ activesupport (= 3.2.11)
22
+ builder (~> 3.0.0)
23
+ erubis (~> 2.7.0)
24
+ journey (~> 1.0.4)
25
+ rack (~> 1.4.0)
26
+ rack-cache (~> 1.2)
27
+ rack-test (~> 0.6.1)
28
+ sprockets (~> 2.2.1)
29
+ activemodel (3.2.11)
30
+ activesupport (= 3.2.11)
31
+ builder (~> 3.0.0)
32
+ activerecord (3.2.11)
33
+ activemodel (= 3.2.11)
34
+ activesupport (= 3.2.11)
35
+ arel (~> 3.0.2)
36
+ tzinfo (~> 0.3.29)
37
+ activeresource (3.2.11)
38
+ activemodel (= 3.2.11)
39
+ activesupport (= 3.2.11)
40
+ activesupport (3.2.11)
41
+ i18n (~> 0.6)
42
+ multi_json (~> 1.0)
43
+ amq-protocol (1.9.2)
44
+ amqp (1.1.8)
45
+ amq-protocol (>= 1.9.2)
46
+ eventmachine
47
+ arel (3.0.3)
48
+ awesome_print (1.2.0)
49
+ builder (3.0.4)
50
+ coffee-rails (3.2.2)
51
+ coffee-script (>= 2.2.0)
52
+ railties (~> 3.2.0)
53
+ coffee-script (2.2.0)
54
+ coffee-script-source
55
+ execjs
56
+ coffee-script-source (1.7.0)
57
+ colorize (0.5.8)
58
+ erubis (2.7.0)
59
+ eventmachine (1.0.3)
60
+ execjs (2.0.2)
61
+ hike (1.2.3)
62
+ i18n (0.6.9)
63
+ journey (1.0.4)
64
+ jquery-rails (3.1.0)
65
+ railties (>= 3.0, < 5.0)
66
+ thor (>= 0.14, < 2.0)
67
+ json (1.8.1)
68
+ mail (2.4.4)
69
+ i18n (>= 0.4.0)
70
+ mime-types (~> 1.16)
71
+ treetop (~> 1.4.8)
72
+ mime-types (1.25.1)
73
+ multi_json (1.8.4)
74
+ open4 (1.3.2)
75
+ polyglot (0.3.4)
76
+ rack (1.4.5)
77
+ rack-cache (1.2)
78
+ rack (>= 0.4)
79
+ rack-ssl (1.3.3)
80
+ rack
81
+ rack-test (0.6.2)
82
+ rack (>= 1.0)
83
+ rails (3.2.11)
84
+ actionmailer (= 3.2.11)
85
+ actionpack (= 3.2.11)
86
+ activerecord (= 3.2.11)
87
+ activeresource (= 3.2.11)
88
+ activesupport (= 3.2.11)
89
+ bundler (~> 1.0)
90
+ railties (= 3.2.11)
91
+ railties (3.2.11)
92
+ actionpack (= 3.2.11)
93
+ activesupport (= 3.2.11)
94
+ rack-ssl (~> 1.3.2)
95
+ rake (>= 0.8.7)
96
+ rdoc (~> 3.4)
97
+ thor (>= 0.14.6, < 2.0)
98
+ rake (10.1.1)
99
+ rdoc (3.12.2)
100
+ json (~> 1.4)
101
+ ruby-progressbar (1.0.2)
102
+ sass (3.2.14)
103
+ sass-rails (3.2.6)
104
+ railties (~> 3.2.0)
105
+ sass (>= 3.1.10)
106
+ tilt (~> 1.3)
107
+ sprockets (2.2.2)
108
+ hike (~> 1.2)
109
+ multi_json (~> 1.0)
110
+ rack (~> 1.0)
111
+ tilt (~> 1.1, != 1.3.0)
112
+ sqlite3 (1.3.9)
113
+ thor (0.18.1)
114
+ tilt (1.4.1)
115
+ treetop (1.4.15)
116
+ polyglot
117
+ polyglot (>= 0.3.1)
118
+ tzinfo (0.3.38)
119
+ uglifier (2.4.0)
120
+ execjs (>= 0.3.0)
121
+ json (>= 1.8.0)
122
+ uuidtools (2.1.3)
123
+ yajl-ruby (1.1.0)
124
+
125
+ PLATFORMS
126
+ ruby
127
+
128
+ DEPENDENCIES
129
+ coffee-rails (~> 3.2.1)
130
+ gorgon!
131
+ jquery-rails
132
+ rails (= 3.2.11)
133
+ sass-rails (~> 3.2.3)
134
+ sqlite3
135
+ uglifier (>= 1.0.3)