proby_notifier 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- proby_notifier (1.0.0)
4
+ proby_notifier (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -46,13 +46,19 @@ module ProbyNotifier
46
46
  #
47
47
  # @param [String] proby_task_id The id of the task to be notified. If nil, the
48
48
  # value of the +PROBY_TASK_ID+ environment variable will be used.
49
- def send_finish_notification(proby_task_id=nil)
50
- send_notification('/finish', proby_task_id)
49
+ # @param [Hash] options The options for the finish notification
50
+ # @option options [Boolean] :failed true if this task run resulted in some sort of failure. Setting
51
+ # this parameter to true will trigger a notification to be sent to
52
+ # the alarms configured for the given task. Defaults to false.
53
+ # @option options [String] :error_message A string message describing the failure that occurred.
54
+ # 1,000 character limit.
55
+ def send_finish_notification(proby_task_id=nil, options={})
56
+ send_notification('/finish', proby_task_id, options)
51
57
  end
52
58
 
53
59
  private
54
60
 
55
- def send_notification(type, proby_task_id)
61
+ def send_notification(type, proby_task_id, options={})
56
62
  if @api_key.nil?
57
63
  logger.warn "ProbyNotifier: No notification sent because API key is not set"
58
64
  return nil
@@ -67,11 +73,13 @@ module ProbyNotifier
67
73
  url = BASE_URL + proby_task_id + type
68
74
  uri = URI.parse(url)
69
75
  req = Net::HTTP::Post.new(uri.path, {'api_key' => @api_key})
76
+ req.set_form_data(options)
70
77
 
71
78
  http = Net::HTTP.new(uri.host, uri.port)
72
79
  http.open_timeout = 3
73
80
  http.read_timeout = 3
74
81
  http.use_ssl = true
82
+
75
83
  res = http.start { |h| h.request(req) }
76
84
  return res.code.to_i
77
85
  rescue Exception => e
@@ -47,11 +47,18 @@ module ProbyNotifier
47
47
  end
48
48
 
49
49
  def around_perform_proby(*args)
50
+ failed = false
51
+ error_message = nil
50
52
  _proby_id = proby_id(*args)
51
53
  ProbyNotifier.send_start_notification(_proby_id)
52
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
53
60
  ensure
54
- ProbyNotifier.send_finish_notification(_proby_id)
61
+ ProbyNotifier.send_finish_notification(_proby_id, :failed => failed, :error_message => error_message)
55
62
  end
56
63
  end
57
64
  end
@@ -1,3 +1,3 @@
1
1
  module ProbyNotifier
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -40,6 +40,11 @@ class ProbyNotifierTest < Test::Unit::TestCase
40
40
  assert_equal 200, ProbyNotifier.send_finish_notification("abc123xyz456")
41
41
  end
42
42
 
43
+ should "send a finish notification with options if options are specified" do
44
+ FakeWeb.register_uri(:post, "https://proby.signalhq.com/tasks/abc123xyz456/finish", :status => ["200", "Success"])
45
+ assert_equal 200, ProbyNotifier.send_finish_notification("abc123xyz456", :failed => true, :error_message => "something bad happened")
46
+ end
47
+
43
48
  should "send a finish notification if a task_id is specified in an environment variable" do
44
49
  ENV['PROBY_TASK_ID'] = "iii999ooo222"
45
50
  FakeWeb.register_uri(:post, "https://proby.signalhq.com/tasks/iii999ooo222/finish", :status => ["200", "Success"])
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proby_notifier
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.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: 2011-09-17 00:00:00 -05:00
19
+ date: 2011-10-11 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency