proby 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  *.swp
2
- doc
3
2
  .yardoc
3
+ doc
4
+ pkg
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- proby (2.0.0)
4
+ proby (2.1.0)
5
5
  chronic (~> 0.6.7)
6
6
  httparty (~> 0.8.1)
7
7
  multi_json (~> 1.2.0)
@@ -16,6 +16,9 @@ GEM
16
16
  multi_json (~> 1.0)
17
17
  multi_xml
18
18
  json (1.6.6)
19
+ metaclass (0.0.1)
20
+ mocha (0.10.5)
21
+ metaclass (~> 0.0.1)
19
22
  multi_json (1.2.0)
20
23
  multi_xml (0.4.4)
21
24
  rake (0.9.2.2)
@@ -30,6 +33,7 @@ DEPENDENCIES
30
33
  bundler (>= 1.0.0)
31
34
  fakeweb (~> 1.3.0)
32
35
  json (~> 1.6.6)
36
+ mocha (~> 0.10.5)
33
37
  proby!
34
38
  rake (~> 0.9.0)
35
39
  shoulda (~> 2.11.3)
data/HISTORY.md ADDED
@@ -0,0 +1,9 @@
1
+ 2.1.0
2
+ -----
3
+ * Added Proby.monitor method
4
+
5
+ 2.0.0
6
+ -----
7
+ * Initial import from proby_notifier codebase.
8
+ * Re-wrote core internals.
9
+ * Added Proby::ProbyTask to wrap the Task API.
data/README.md CHANGED
@@ -39,15 +39,19 @@ In addition, you can optionally give Proby a logger to use.
39
39
 
40
40
  Sending Notifications
41
41
  ---------------------
42
- To send a start notification
42
+ The easiest way to have Proby monitor your task is by wrapping your code in a call to Proby's `monitor` function.
43
43
 
44
- Proby.send_start_notification(task_api_id)
44
+ Proby.monitor(task_api_id) do
45
+ # Do something here
46
+ end
45
47
 
46
- To send a finish notification
48
+ You can also send the start and finish notifications manually via calls to `send_start_notification` and `send_finish_notification`.
47
49
 
50
+ Proby.send_start_notification(task_api_id)
51
+ # Do something here
48
52
  Proby.send_finish_notification(task_api_id)
49
53
 
50
- Specifying the `task_api_id` when calling the notification methods is optional. If it is not provided,
54
+ Specifying the `task_api_id` when calling any of the the notification methods is optional. If it is not provided,
51
55
  Proby will use the value of the `PROBY_TASK_ID` environment variable. If no task id is specified
52
56
  in the method call, and no value is set in the `PROBY_TASK_ID` environment variable, then no notification
53
57
  will be sent.
@@ -47,18 +47,10 @@ module Proby
47
47
  end
48
48
 
49
49
  def around_perform_proby(*args)
50
- failed = false
51
- error_message = nil
52
50
  _proby_id = proby_id(*args)
53
- Proby.send_start_notification(_proby_id)
54
- yield
55
- rescue Exception => e
56
- failed = true
57
- error_message = "#{e.class.name}: #{e.message}"
58
- error_message << "\n#{e.backtrace.join("\n")}" if e.backtrace
59
- raise e
60
- ensure
61
- Proby.send_finish_notification(_proby_id, :failed => failed, :error_message => error_message)
51
+ Proby.monitor(_proby_id) do
52
+ yield
53
+ end
62
54
  end
63
55
  end
64
56
  end
data/lib/proby/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Proby
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
data/lib/proby.rb CHANGED
@@ -70,6 +70,28 @@ module Proby
70
70
  Notifier.send_notification('finish', proby_task_id, options)
71
71
  end
72
72
 
73
+ # Surround the block of code with Proby start and finish notifications. If an exception
74
+ # is raised in the block of code, then the task will be marked as failed, and the
75
+ # exception's message and backtrace will be sent to Proby as the task's error message.
76
+ #
77
+ # @param [String] proby_task_id The id of the task to be notified. If nil, the
78
+ # value of the +PROBY_TASK_ID+ environment variable will be used.
79
+ def monitor(proby_task_id=nil)
80
+ failed = false
81
+ error_message = nil
82
+ begin
83
+ Proby.send_start_notification(proby_task_id)
84
+ yield
85
+ rescue Exception => e
86
+ failed = true
87
+ error_message = "#{e.class.name}: #{e.message}"
88
+ error_message << "\n#{e.backtrace.join("\n")}" if e.backtrace
89
+ raise e
90
+ ensure
91
+ Proby.send_finish_notification(proby_task_id, :failed => failed, :error_message => error_message)
92
+ end
93
+ end
94
+
73
95
  end
74
96
  end
75
97
 
data/proby.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency "yard", "~> 0.6.4"
26
26
  s.add_development_dependency "bluecloth", "~> 2.1.0"
27
27
  s.add_development_dependency "fakeweb", "~> 1.3.0"
28
+ s.add_development_dependency "mocha", "~> 0.10.5"
28
29
  s.add_development_dependency "shoulda", "~> 2.11.3"
29
30
  s.add_development_dependency "json", "~> 1.6.6"
30
31
 
@@ -55,6 +55,21 @@ class NotifierTest < Test::Unit::TestCase
55
55
  FakeWeb.register_uri(:post, Proby::ProbyHttpApi.base_uri + "/api/v1/tasks/iii999ooo222/finish.json", :status => ["200", "OK"])
56
56
  assert_equal 200, Proby.send_finish_notification
57
57
  end
58
+
59
+ should "send a start and finish notificaiton when using the monitor method" do
60
+ Proby.expects(:send_start_notification).with("abc123xyz456")
61
+ Proby.expects(:send_finish_notification).with() { |param1, param2| param1 == "abc123xyz456" && param2[:failed] == false && param2[:error_message].nil? }
62
+ assert_equal "foo", Proby.monitor("abc123xyz456") { "foo" }
63
+ end
64
+
65
+ should "include error information in the finish notification if the block passed to monitor raises an exception" do
66
+ Proby.expects(:send_start_notification).with("abc123xyz456")
67
+ Proby.expects(:send_finish_notification).with() { |param1, param2| param1 == "abc123xyz456" && param2[:failed] == true && param2[:error_message].include?("This is the error message") }
68
+ e = assert_raise Exception do
69
+ Proby.monitor("abc123xyz456") { raise Exception.new("This is the error message") }
70
+ end
71
+ assert_equal "This is the error message", e.message
72
+ end
58
73
  end
59
74
 
60
75
  end
data/test/test_helper.rb CHANGED
@@ -11,6 +11,7 @@ end
11
11
  require 'test/unit'
12
12
  require 'fakeweb'
13
13
  require 'shoulda'
14
+ require 'mocha'
14
15
 
15
16
  require 'proby'
16
17
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 2.0.0
10
+ version: 2.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Wood
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-04-27 00:00:00 -05:00
19
+ date: 2012-04-30 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -150,6 +150,22 @@ dependencies:
150
150
  - !ruby/object:Gem::Dependency
151
151
  prerelease: false
152
152
  version_requirements: &id009 !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ hash: 61
158
+ segments:
159
+ - 0
160
+ - 10
161
+ - 5
162
+ version: 0.10.5
163
+ type: :development
164
+ requirement: *id009
165
+ name: mocha
166
+ - !ruby/object:Gem::Dependency
167
+ prerelease: false
168
+ version_requirements: &id010 !ruby/object:Gem::Requirement
153
169
  none: false
154
170
  requirements:
155
171
  - - ~>
@@ -161,11 +177,11 @@ dependencies:
161
177
  - 3
162
178
  version: 2.11.3
163
179
  type: :development
164
- requirement: *id009
180
+ requirement: *id010
165
181
  name: shoulda
166
182
  - !ruby/object:Gem::Dependency
167
183
  prerelease: false
168
- version_requirements: &id010 !ruby/object:Gem::Requirement
184
+ version_requirements: &id011 !ruby/object:Gem::Requirement
169
185
  none: false
170
186
  requirements:
171
187
  - - ~>
@@ -177,7 +193,7 @@ dependencies:
177
193
  - 6
178
194
  version: 1.6.6
179
195
  type: :development
180
- requirement: *id010
196
+ requirement: *id011
181
197
  name: json
182
198
  description: A simple library for working with the Proby task monitoring application.
183
199
  email:
@@ -193,6 +209,7 @@ files:
193
209
  - .gitignore
194
210
  - Gemfile
195
211
  - Gemfile.lock
212
+ - HISTORY.md
196
213
  - README.md
197
214
  - Rakefile
198
215
  - lib/proby.rb