capistrano-measure 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb3dbe3012c37df839a3eb8ccc8915297a8de55e
4
- data.tar.gz: 5f5f6f74b3146163a665d1afff70a501b8d18c4f
3
+ metadata.gz: 7985b11ba0b7a76c5839925a75d929a7991222ec
4
+ data.tar.gz: d9d5b4a4bb46921324ffe71b8b4769788bdd5d68
5
5
  SHA512:
6
- metadata.gz: e193eee4d4a3890e4f2e717f045d93eeead51ad227c9986726754a766b7e7b68026325b7331d5242ce612779df7a74e7775f7d9c767a26143d21a84cbd56ff1e
7
- data.tar.gz: 9662f5a7ab726276484c670faac76bf4eb7faa302337221d2ea3ac7db1b1a19c3ab4b2089b775b8bb1c1099da2d74c3fc13e69bfa6d06565c2f8db6cbee2758d
6
+ metadata.gz: 9afca2004487f749ba1863e190f7ec1716362e9fd9df5519293765533849a2a9e9287c72fa8c551240fafde5a0d8f6799739556004720f29e144aaa876c6216d
7
+ data.tar.gz: d9d7958f05359b27fdc8d54d943632572e81a73308d63126047be83b48ff00f169801160c6968efcdc11cf1302a7e7b7346071612d7c9423f0e7aeef11cb9d48
data/README.md CHANGED
@@ -91,8 +91,9 @@ It will append every capistrano execution with similar report
91
91
  You could change threshold time to change the results duration's color.
92
92
 
93
93
  ```ruby
94
- set :alert_threshold, 10 # default 60 sec
95
- set :warning_threshold, 5 # default 30 sec
94
+ set :alert_threshold, 10 # default 60 sec
95
+ set :warning_threshold, 5 # default 30 sec
96
+ set :measure_error_handling, :raise # default :silent
96
97
  ```
97
98
 
98
99
  ## Contributing
@@ -3,6 +3,7 @@ require 'capistrano/measure/version'
3
3
  require 'capistrano/measure/timer'
4
4
  require 'capistrano/measure/log_reporter'
5
5
  require 'capistrano/measure/adapter'
6
+ require 'capistrano/measure/error'
6
7
 
7
8
  case ::Capistrano::Measure::Adapter::capistrano_version
8
9
  when 2
@@ -10,7 +11,7 @@ when 2
10
11
  when 3
11
12
  require 'capistrano/measure/integration/capistrano_3'
12
13
  else
13
- raise 'This version of Capistrano is not supported.'
14
+ raise ::Capistrano::Measure::Error, 'This version of Capistrano is not supported.'
14
15
  end
15
16
 
16
17
  module Capistrano
@@ -11,18 +11,23 @@ module Capistrano
11
11
  def initialize(logger, config)
12
12
  @logger = logger
13
13
  @config = config
14
+ @valid = true
14
15
  end
15
16
 
16
17
  def before_task(task_name)
17
- timer.start(task_name)
18
+ with_error_handling { timer.start(task_name) }
18
19
  end
19
20
 
20
21
  def after_task(task_name)
21
- timer.stop(task_name)
22
+ with_error_handling { timer.stop(task_name) }
22
23
  end
23
24
 
24
25
  def print_report
25
- log_reporter.render(timer.report_events)
26
+ if valid?
27
+ log_reporter.render(timer.report_events)
28
+ else
29
+ log_reporter.render_error("Capistrano::Measure plugin encountered an error during performance evaluation and is not able to present a performance report, in order to `raise` and troubleshoot this error add `set :measure_error_handling, :raise` into your capistrano config")
30
+ end
26
31
  end
27
32
 
28
33
  private
@@ -37,6 +42,21 @@ module Capistrano
37
42
  @timer ||= Capistrano::Measure::Timer.new
38
43
  end
39
44
 
45
+ def debug?
46
+ config.fetch(:measure_error_handling, :silent) == :raise
47
+ end
48
+
49
+ def valid?
50
+ @valid
51
+ end
52
+
53
+ def with_error_handling
54
+ yield
55
+ rescue StandardError => e
56
+ @valid = false
57
+ raise e if debug?
58
+ end
59
+
40
60
  end
41
61
  end
42
62
  end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Measure
3
+ class Error < StandardError; end
4
+ end
5
+ end
@@ -19,18 +19,29 @@ module Capistrano
19
19
  def render(events)
20
20
  return if events.to_a.empty?
21
21
 
22
- log_sepertor
23
- log ColorizedString[" Performance Report"].green
24
- log_sepertor
22
+ with_layout do
23
+ events.each do |event|
24
+ log "#{'..' * event.indent}#{event.name} #{colorize_time(event.elapsed_time)}"
25
+ end
26
+ end
27
+ end
25
28
 
26
- events.each do |event|
27
- log "#{'..' * event.indent}#{event.name} #{colorize_time(event.elapsed_time)}"
29
+ def render_error(message)
30
+ with_layout do
31
+ @logger.error message
28
32
  end
29
- log_sepertor
30
33
  end
31
34
 
32
35
  private
33
36
 
37
+ def with_layout
38
+ log_sepertor
39
+ log ColorizedString[" Performance Report"].green
40
+ log_sepertor
41
+ yield
42
+ log_sepertor
43
+ end
44
+
34
45
  def log_sepertor
35
46
  log "=" * 60
36
47
  end
@@ -42,7 +42,7 @@ module Capistrano
42
42
  end
43
43
 
44
44
  def report_events
45
- raise 'Performance measure is not completed' unless @open_events.empty?
45
+ raise ::Capistrano::Measure::Error, "Performance evaluation is not yet completed, as there are events still open: #{@open_events.map(&:name).join(', ')}" unless @open_events.empty?
46
46
  return to_enum(__callee__) unless block_given?
47
47
 
48
48
  (events + [Event.new]).each_cons(2) do |event, next_event|
@@ -55,7 +55,7 @@ module Capistrano
55
55
  def close_event(event_name)
56
56
  event = Event.new(event_name, :stop, Time.now, @indent-1)
57
57
  open_event = @open_events.last
58
- raise "You're trying to stop unstarted event" unless event.eq?(open_event)
58
+ raise ::Capistrano::Measure::Error, "Cannot estimate time for event `#{event_name}`" unless event.eq?(open_event)
59
59
 
60
60
  event.elapsed_time = (event.time - open_event.time).to_i
61
61
  event
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Measure
3
- VERSION = "0.9.1"
3
+ VERSION = "0.10.0"
4
4
  end
5
5
  end
@@ -20,7 +20,31 @@ describe Capistrano::Measure::Adapter do
20
20
 
21
21
  subject.print_report
22
22
 
23
- expect(logger.to_s).not_to be_empty
23
+ expect(logger.to_s).to include("Performance Report")
24
+ expect(logger.to_s).to include("root_task")
25
+ expect(logger.to_s).to include("..sub_task")
26
+ expect(logger.to_s).to include("....sub_task1")
27
+ end
28
+
29
+ it "doesn't rise any errors by default" do
30
+ subject.before_task('root_task')
31
+ subject.after_task('sub_task')
32
+
33
+ subject.print_report
34
+
35
+ expect(logger.to_s).to include("Capistrano::Measure plugin encountered an error during performance evaluation")
36
+ end
37
+
38
+ it "raises an error in debug mode (and interrupts the deployment)" do
39
+ config[:measure_error_handling] = :raise
40
+
41
+ expect {
42
+ subject.before_task('root_task')
43
+ subject.after_task('sub_task')
44
+
45
+ subject.print_report
46
+ }.to raise_error(::Capistrano::Measure::Error)
47
+
24
48
  end
25
49
 
26
50
  describe "::capistrano_version" do
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'capistrano/measure/error'
2
3
  require 'capistrano/measure/timer'
3
4
 
4
5
  describe Capistrano::Measure::Timer do
@@ -75,14 +76,14 @@ describe Capistrano::Measure::Timer do
75
76
  end
76
77
 
77
78
  it "should raise exception with unstarted event" do
78
- expect{ subject.stop('test123') }.to raise_error(RuntimeError)
79
+ expect{ subject.stop('test123') }.to raise_error(::Capistrano::Measure::Error)
79
80
  end
80
81
  end
81
82
 
82
83
  describe "#report_events" do
83
84
  it "should raise exception if called in the middle of process" do
84
85
  subject.start('test')
85
- expect{ subject.report_events }.to raise_error(RuntimeError)
86
+ expect{ subject.report_events }.to raise_error(::Capistrano::Measure::Error)
86
87
  end
87
88
 
88
89
  context "in completed state" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-measure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artūrs Mekšs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-21 00:00:00.000000000 Z
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -120,6 +120,7 @@ files:
120
120
  - lib/capistrano-measure.rb
121
121
  - lib/capistrano/measure.rb
122
122
  - lib/capistrano/measure/adapter.rb
123
+ - lib/capistrano/measure/error.rb
123
124
  - lib/capistrano/measure/integration/capistrano_2.rb
124
125
  - lib/capistrano/measure/integration/capistrano_3.rb
125
126
  - lib/capistrano/measure/log_reporter.rb