snooze 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-head
7
+ - jruby-18mode
8
+ - jruby-19mode
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+ - ruby-head
12
+ - 1.8.7
13
+ - ree
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: jruby-19mode
17
+ - rvm: rbx-19mode
18
+ - rvm: jruby-head
19
+ - rvm: ruby-head
20
+ notifications:
21
+ email:
22
+ - contact@snooze.io
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
@@ -1,13 +1,35 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Snooze (0.0.1)
4
+ snooze (1.0.0)
5
+ faraday
5
6
 
6
7
  GEM
7
- remote: http://rubygems.org/
8
+ remote: https://rubygems.org/
8
9
  specs:
10
+ coderay (1.0.8)
9
11
  diff-lcs (1.2.1)
12
+ faraday (0.8.7)
13
+ multipart-post (~> 1.1)
14
+ guard (1.6.2)
15
+ listen (>= 0.6.0)
16
+ lumberjack (>= 1.0.2)
17
+ pry (>= 0.9.10)
18
+ terminal-table (>= 1.4.3)
19
+ thor (>= 0.14.6)
20
+ guard-rspec (2.4.0)
21
+ guard (>= 1.1)
22
+ rspec (~> 2.11)
23
+ listen (0.7.2)
24
+ lumberjack (1.0.2)
25
+ method_source (0.8.1)
26
+ multipart-post (1.2.0)
27
+ pry (0.9.12)
28
+ coderay (~> 1.0.5)
29
+ method_source (~> 0.8)
30
+ slop (~> 3.4)
10
31
  rake (10.0.3)
32
+ rb-fsevent (0.9.3)
11
33
  rspec (2.13.0)
12
34
  rspec-core (~> 2.13.0)
13
35
  rspec-expectations (~> 2.13.0)
@@ -16,11 +38,16 @@ GEM
16
38
  rspec-expectations (2.13.0)
17
39
  diff-lcs (>= 1.1.3, < 2.0)
18
40
  rspec-mocks (2.13.0)
41
+ slop (3.4.3)
42
+ terminal-table (1.4.5)
43
+ thor (0.17.0)
19
44
 
20
45
  PLATFORMS
21
46
  ruby
22
47
 
23
48
  DEPENDENCIES
24
- Snooze!
49
+ guard-rspec
25
50
  rake
51
+ rb-fsevent
26
52
  rspec (~> 2.8)
53
+ snooze!
@@ -0,0 +1,14 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ # Files that affect global scope -> run all specs when they change
6
+ watch(%r{^lib/snooze.rb$}) { 'spec' }
7
+ watch('spec/spec_helper.rb') { 'spec' }
8
+ watch('.rspec') { 'spec' }
9
+ watch('Guardfile.lock') { 'spec' }
10
+
11
+ # Specific files -> only run the associated spec file when they change
12
+ watch(%r{^spec/.+_spec\.rb$})
13
+ watch(%r{^lib/snooze/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
14
+ end
data/LICENSE CHANGED
@@ -1,20 +1,62 @@
1
- Copyright (c) 2013-2014 Bart ten Brinke
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ This product depends on Faraday written by Rick Olson and Zack Hobson
2
+ and distributed under an MIT license.
3
+ See https://github.com/lostisland/faraday/blob/master/LICENSE.md
4
+ Copyright (c) 2009-2013 Rick Olson, Zack Hobson
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files
8
+ (the "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to permit
11
+ persons to whom the Software is furnished to do so, subject to the
12
+ following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
24
+
25
+ All other components of this product are copyright (c) 2013-2014 Bart ten
26
+ Brinke - Retrosync. All rights reserved.
27
+
28
+ Certain inventions disclosed in this file may be claimed within
29
+ patents owned or patent applications filed by Retrosync, or third
30
+ parties.
31
+
32
+ Subject to the terms of this notice, Retrosync grants you a
33
+ nonexclusive, nontransferable license, without the right to
34
+ sublicense, to (a) install and execute one copy of these files on any
35
+ number of workstations owned or controlled by you and (b) distribute
36
+ verbatim copies of these files to third parties. As a condition to the
37
+ foregoing grant, you must provide this notice along with each copy you
38
+ distribute and you must not remove, alter, or obscure this notice. All
39
+ other use, reproduction, modification, distribution, or other
40
+ exploitation of these files is strictly prohibited, except as may be set
41
+ forth in a separate written license agreement between you and New
42
+ Relic. The terms of any such license agreement will control over this
43
+ notice. The license stated above will be automatically terminated and
44
+ revoked if you exceed its scope or violate any of the terms of this
45
+ notice.
46
+
47
+ This License does not grant permission to use the trade names,
48
+ trademarks, service marks, or product names of Retrosync, except as
49
+ required for reasonable and customary use in describing the origin of
50
+ this file and reproducing the content of this notice. You may not
51
+ mark or brand this file with any trade name, trademarks, service
52
+ marks, or product names other than the original brand (if any)
53
+ provided by Retrosync.
54
+
55
+ Unless otherwise expressly agreed by Retrosync in a separate written
56
+ license agreement, these files are provided AS IS, WITHOUT WARRANTY OF
57
+ ANY KIND, including without any implied warranties of MERCHANTABILITY,
58
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
59
+ condition to your use of these files, you are solely responsible for
60
+ such use. Retrosync will have no liability to you for direct,
61
+ indirect, consequential, incidental, special, or punitive damages or
62
+ for lost profits or data.
@@ -4,20 +4,50 @@ For devops who run recurring jobs like rake tasks or bas scripts,
4
4
  Snooze.io is a notification service that tells you when something is wrong.
5
5
  Unlike just alerting when a job breaks, Snooze also alerts when a job did not run at all.
6
6
 
7
+ * Simple heartbeat monitoring for all your tasks / scripts
8
+ * Runs on all rubies {<img src="https://travis-ci.org/retrosync/snooze.png?branch=master" alt="Build Status" />}[https://travis-ci.org/retrosync/snooze]
9
+ * Runs from bash
10
+
7
11
  == Installation & basic usage
8
12
 
9
13
  Log in to http://www.snooze.io and create your account
10
14
 
11
- Install Snooze a Ruby gem:
15
+ Install the Snooze gem:
12
16
 
13
17
  $ gem install snooze
14
18
 
15
- TODO: ADD More info here
19
+ Call the Snooze gem from the command line with your clock id to Snooze a clock:
20
+
21
+ $ snooze 1234-1234-abcd-abcd
22
+
23
+ == Advanced usage
24
+ Test the Snoozing of a clock and the connection to Snooze.io:
25
+
26
+ $ snooze --dry-run 1234-1234-abcd-abcd
27
+
28
+ Get more debug output while Snoozing of a clock:
29
+
30
+ $ snooze --verbose 1234-1234-abcd-abcd
31
+
32
+ Snoozing a clock from Ruby / Rake task:
33
+
34
+ require 'snooze'
35
+ snooze_instance = Snooze::Button.new('1234-1234-abcd-abcd')
36
+ snooze_instance.snooze!
37
+
38
+ Catching exceptions in your Ruby application. If your code does not throw an exception,
39
+ your clock will automatically be Snoozed.
40
+
41
+ require 'snooze'
42
+ snooze_instance = Snooze::Button.new('1234-1234-abcd-abcd')
43
+ snooze_instance.with_backtrace do
44
+ puts 'your code goes here'
45
+ end
16
46
 
17
47
  == Additional information
18
48
 
19
49
  Snooze was designed and built by Bart ten Brinke from Retrosync.
20
- If you have any issues, the fastest way to contact me is either through github or via email. (contact@snooze.io)
50
+ If you have any issues, the fastest way to contact me is either through github or via email: contact@snooze.io
21
51
 
22
52
  * Snooze homepage: http://www.snooze.io
23
53
  * Retrosync homepage: http://www.retrosync.com
data/bin/snooze CHANGED
@@ -3,6 +3,42 @@
3
3
 
4
4
  $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
5
5
  require 'snooze'
6
+ require 'optparse'
6
7
 
7
- puts "Snooze gem, by Bart ten Brinke - version #{Snooze::VERSION}"
8
- puts "Website: http://snooze.io"
8
+ ## Variables
9
+ allowed_actions = ['snooze', 'backtrace', 'ping']
10
+ options = {}
11
+
12
+ optparse = OptionParser.new do |opts|
13
+ # Set a banner, displayed at the top
14
+ # of the help screen.
15
+ opts.banner = "Snooze gem, by Bart ten Brinke - version #{Snooze::VERSION}\nWebsite: http://snooze.io\n\n:Usage: snooze [options] clock_id\n\n"
16
+
17
+ # Define the options, and what they do
18
+ options[:verbose] = false
19
+ opts.on( '-v', '--verbose', 'Output more information' ) do
20
+ options[:verbose] = true
21
+ end
22
+
23
+ options[:dry_run] = false
24
+ opts.on( '-d', '--dry-run', 'Go through all the normal steps, but not actually Snooze anything.' ) do
25
+ options[:dry_run] = true
26
+ end
27
+
28
+ opts.on( '-h', '--help', 'Display this screen' ) do
29
+ puts opts
30
+ exit
31
+ end
32
+ end
33
+
34
+ optparse.parse!
35
+ if ARGV.empty? || ARGV.length != 1
36
+ puts optparse
37
+ exit(-1)
38
+ end
39
+
40
+ clock_id = ARGV[0]
41
+
42
+ require 'snooze'
43
+ snooze_instance = Snooze::Button.new(clock_id, options)
44
+ exit(snooze_instance.snooze!)
@@ -1,7 +1,14 @@
1
1
  module Snooze
2
2
  # The current version of snooze.
3
3
  # Do not change the value by hand; it will be updated automatically by the gem release script.
4
- VERSION = "0.2.0"
4
+ VERSION = "1.0.0"
5
+
6
+ API_HOST = 'https://api.snooze.io'
7
+ API_PATH = 'api'
5
8
  end
6
9
 
7
- #require 'snooze/controller'
10
+ require 'faraday'
11
+ require 'uri'
12
+ require 'snooze/connection_error'
13
+ require 'snooze/button'
14
+ require 'snooze/post'
@@ -0,0 +1,53 @@
1
+ class Snooze::Button
2
+
3
+ attr_reader :dry_run, :clock_id, :method, :verbose
4
+
5
+ def initialize(clock_id, options = {})
6
+ @clock_id = clock_id
7
+ @dry_run = options[:dry_run] || false
8
+ @method = :snooze!
9
+ @verbose = options[:verbose] || false
10
+
11
+ if @dry_run
12
+ @method = :ping!
13
+ @verbose = true
14
+ end
15
+ end
16
+
17
+ # Send snooze! or ping! to Snooze
18
+ def snooze!
19
+ log "Sending #{@method} to Snooze.io"
20
+ handle_post_response { Snooze::Post.send(@method, @clock_id) }
21
+ end
22
+
23
+ # With backtrace capturing do
24
+ def with_backtrace(&block)
25
+ begin
26
+ log "Yielding backtrace block"
27
+ yield if block_given?
28
+ Snooze::Post.snooze!
29
+ rescue Exception => detail
30
+ handle_post_response { Snooze::Post.exception!(@clock_id, detail.backtrace.join("\n ")) }
31
+ end
32
+ end
33
+
34
+ private
35
+ # Handle a post response
36
+ # The block given should be a Snooze::Post class function.
37
+ def handle_post_response(&block)
38
+ exit_code = 1
39
+ begin
40
+ response = yield
41
+ exit_code = 0 if response.success?
42
+ log "Error: Snooze returned status error #{response.status}" unless response.success?
43
+ log "Snooze returned status message: #{response.body}" if @verbose
44
+ rescue Snooze::ConnectionError
45
+ log "Error: Snooze server is unreachable"
46
+ end
47
+ exit_code
48
+ end
49
+
50
+ def log(msg)
51
+ puts msg if @verbose
52
+ end
53
+ end
@@ -0,0 +1,2 @@
1
+ class Snooze::ConnectionError < StandardError
2
+ end
@@ -0,0 +1,58 @@
1
+ class Snooze::Post
2
+
3
+ # Setup the api host URI for the given action
4
+ def self.generate_uri_from_action(action)
5
+ URI.parse("#{Snooze::API_HOST}/#{Snooze::API_PATH}/#{action}")
6
+ end
7
+
8
+ # Setup the connection
9
+ def self.setup_connection(uri)
10
+ ::Faraday.new(:url => uri)
11
+ end
12
+
13
+ # Execute an HTTP post
14
+ def self.execute!(action, post_body, retries = 4)
15
+ uri = self.generate_uri_from_action(action)
16
+ response = nil
17
+
18
+ begin
19
+ connection = self.setup_connection(uri)
20
+
21
+ response = connection.post uri.path do |request|
22
+ request.headers['Content-Type'] = 'application/json'
23
+ request.options[:timeout] = 5
24
+ request.options[:open_timeout] = 2
25
+ request.body = post_body
26
+ end
27
+
28
+ raise Faraday::Error::ConnectionFailed.new('') if response.status == 500
29
+ rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed, Faraday::Error::ClientError, Faraday::Error => e
30
+ raise Snooze::ConnectionError if retries <= 0
31
+ sleep_for_a_while(5 - retries)
32
+ response = self.execute!(action, post_body, retries-1)
33
+ end
34
+
35
+ response
36
+ end
37
+
38
+ # Ping Snooze
39
+ def self.ping!(clock_id)
40
+ self.execute!('ping', "{ \"id\":\"#{clock_id}\" }" )
41
+ end
42
+
43
+ # Snooze an alarm
44
+ def self.snooze!(clock_id)
45
+ self.execute!('snooze', "{ \"id\":\"#{clock_id}\" }")
46
+ end
47
+
48
+ # Pass an exception backtrace to Snooze
49
+ def self.exception!(clock_id, backtrace="")
50
+ self.execute!('exception', "{ \"id\":\"#{clock_id}\", \"backtrace\":\"#{backtrace}\" }")
51
+ end
52
+
53
+ private
54
+ def self.sleep_for_a_while(seconds)
55
+ sleep(seconds)
56
+ end
57
+
58
+ end
@@ -2,8 +2,8 @@ Gem::Specification.new do |s|
2
2
  s.name = "snooze"
3
3
 
4
4
  # Do not set the version and date field manually, this is done by the release script
5
- s.version = "0.2.0"
6
- s.date = "2013-03-05"
5
+ s.version = "1.0.0"
6
+ s.date = "2013-05-03"
7
7
 
8
8
  s.bindir = 'bin'
9
9
  s.executables = ['snooze']
@@ -19,8 +19,12 @@ Gem::Specification.new do |s|
19
19
  s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
20
20
  s.extra_rdoc_files = ['README.rdoc']
21
21
 
22
+ s.add_dependency('faraday')
23
+
22
24
  s.add_development_dependency('rake')
23
25
  s.add_development_dependency('rspec', '~> 2.8')
26
+ s.add_development_dependency('guard-rspec')
27
+ s.add_development_dependency('rb-fsevent')
24
28
 
25
29
  s.authors = ['Bart ten Brinke']
26
30
  s.email = ['contact@snooze.io']
@@ -28,6 +32,6 @@ Gem::Specification.new do |s|
28
32
 
29
33
  # The files and test_files directives are set automatically by the release script.
30
34
  # Do not change them by hand, but make sure to add the files to the git repository.
31
- s.files = %w(.gitignore Gemfile Gemfile.lock LICENSE README.rdoc Rakefile bin/snooze lib/snooze.rb snooze.gemspec spec/spec_helper.rb tasks/github-gem.rake)
32
- s.test_files = %w()
35
+ s.files = %w(.gitignore .travis.yml Gemfile Gemfile.lock Guardfile LICENSE README.rdoc Rakefile bin/snooze lib/snooze.rb lib/snooze/button.rb lib/snooze/connection_error.rb lib/snooze/post.rb snooze.gemspec spec/spec_helper.rb spec/unit/button_spec.rb spec/unit/post_spec.rb tasks/github-gem.rake)
36
+ s.test_files = %w(spec/unit/button_spec.rb spec/unit/post_spec.rb)
33
37
  end
@@ -7,4 +7,12 @@ require 'snooze'
7
7
  # Include all files in the spec_helper directory
8
8
  Dir[File.dirname(__FILE__) + "/lib/**/*.rb"].each do |file|
9
9
  require file
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.color_enabled = true
16
+ config.filter_run :focus
17
+ config.order = 'random'
10
18
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Snooze::Button, 'button' do
4
+ let (:button) { Snooze::Button.new('8765-1234') }
5
+ let (:response) { Faraday::Response.new(:status => 200)}
6
+
7
+ it "should initialize a dry run correctly" do
8
+ dry_button = Snooze::Button.new('8765-1234', :dry_run => true)
9
+ dry_button.dry_run.should == true
10
+ end
11
+
12
+ it "should capture the clock id" do
13
+ button.clock_id.should == '8765-1234'
14
+ end
15
+
16
+ it "should call ping! if dry run" do
17
+ button = Snooze::Button.new('8765-1234', :dry_run => true)
18
+ Snooze::Post.should_receive(:ping!).once.and_return(response)
19
+ button.snooze!
20
+ end
21
+
22
+ it "should support with_backtrace_do" do
23
+ Snooze::Post.should_receive(:exception!).once.and_return(response)
24
+ button.with_backtrace do
25
+ raise 'terrible exception!'
26
+ end
27
+ end
28
+
29
+ describe "snooze! status code handling" do
30
+ it "should support 200" do
31
+ Snooze::Post.should_receive(:snooze!).once.and_return(response)
32
+ button.snooze!.should == 0
33
+ end
34
+
35
+ [500,404,403,100].each do |status_code|
36
+ it "should support #{status_code}" do
37
+ Snooze::Post.should_receive(:snooze!).once.and_return( Faraday::Response.new(:status => status_code) )
38
+ button.snooze!.should == 1
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe Snooze::Post do
4
+ let (:test_connection) {
5
+ Faraday.new do |builder|
6
+ builder.adapter :test do |stub|
7
+ stub.post('api/action') { [200, {}, ''] }
8
+ stub.post('api/ping') { [200, {:id=>"1234-5678"}, ''] }
9
+ stub.post('api/snooze') { [200, {:id=>"1234-5678"}, ''] }
10
+ stub.post('api/exception') { [200, {:id=>"1234-5678", :backtrace => "error\nwith\newlines"}, ''] }
11
+ end
12
+ end
13
+ }
14
+
15
+ it "should generate the correct path" do
16
+ Snooze::Post.generate_uri_from_action('test').to_s.should == 'https://api.snooze.io/api/test'
17
+ end
18
+
19
+ it "should setup a faraday connection" do
20
+ connection = Snooze::Post.setup_connection('http://www.example.com/')
21
+ connection.is_a?(::Faraday::Connection).should be_true
22
+ connection.url_prefix.to_s.should == 'http://www.example.com/'
23
+ end
24
+
25
+ it "should post to an action URL" do
26
+ Snooze::Post.stub!(:setup_connection).and_return(test_connection)
27
+
28
+ response = Snooze::Post.execute!('action', {:test_data => true})
29
+ response.status.should == 200
30
+ end
31
+
32
+ describe 'ping' do
33
+ it "should post to the ping URL" do
34
+ Snooze::Post.stub!(:setup_connection).and_return(test_connection)
35
+ response = Snooze::Post.ping!('1234-5678')
36
+ response.status.should == 200
37
+ end
38
+
39
+ it "should handle unkown clock_ids" do
40
+ test_connection = Faraday.new do |builder|
41
+ builder.adapter :test do |stub|
42
+ stub.post('api/ping') { [404, {:id=>"1234-5679"}, ''] }
43
+ end
44
+ end
45
+
46
+ Snooze::Post.stub!(:setup_connection).and_return(test_connection)
47
+ response = Snooze::Post.ping!('1234-5679')
48
+ response.status.should == 404
49
+ end
50
+ end
51
+
52
+ describe 'snooze' do
53
+ it "should post to the snooze URL" do
54
+ Snooze::Post.stub!(:setup_connection).and_return(test_connection)
55
+ response = Snooze::Post.snooze!('1234-5678')
56
+ response.status.should == 200
57
+ end
58
+
59
+ it "should handle unkown clock_ids" do
60
+ test_connection = Faraday.new do |builder|
61
+ builder.adapter :test do |stub|
62
+ stub.post('api/snooze') { [404, {:id=>"1234-5679"}, ''] }
63
+ end
64
+ end
65
+
66
+ Snooze::Post.stub!(:setup_connection).and_return(test_connection)
67
+ response = Snooze::Post.snooze!('1234-5679')
68
+ response.status.should == 404
69
+ end
70
+ end
71
+
72
+ describe 'exception' do
73
+ it "should post a backtrace to the snooze URL" do
74
+ Snooze::Post.stub!(:setup_connection).and_return(test_connection)
75
+ response = Snooze::Post.exception!('1234-5678', "error\nwith\newlines")
76
+ response.status.should == 200
77
+ end
78
+
79
+ it "should handle unkown clock_ids" do
80
+ test_connection = Faraday.new do |builder|
81
+ builder.adapter :test do |stub|
82
+ stub.post('api/exception') { [404, {:id=>"1234-5679", :backtrace => "error\nwith\newlines"}, ''] }
83
+ end
84
+ end
85
+
86
+ Snooze::Post.stub!(:setup_connection).and_return(test_connection)
87
+ response = Snooze::Post.exception!('1234-5679', "error\nwith\newlines")
88
+ response.status.should == 404
89
+ end
90
+ end
91
+
92
+ describe 'execute!' do
93
+ it "should retry five times" do
94
+ exception = Faraday::Error::TimeoutError.new('')
95
+ Snooze::Post.stub!(:setup_connection).and_raise(exception)
96
+ Snooze::Post.stub!(:sleep_for_a_while).and_return(true)
97
+ Snooze::Post.should_receive(:execute!).exactly(5).times.and_call_original
98
+ expect { Snooze::Post.execute!('noop', {:a => 'b'}) }.to raise_error(Snooze::ConnectionError)
99
+ end
100
+
101
+ end
102
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snooze
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rake
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -43,6 +59,38 @@ dependencies:
43
59
  - - ~>
44
60
  - !ruby/object:Gem::Version
45
61
  version: '2.8'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-fsevent
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
46
94
  description: ! " For devops who run recurring jobs like rake tasks or bas scripts,\n
47
95
  \ Snooze.io is a notification service that tells you when something is wrong.\n
48
96
  \ Unlike just alerting when a job breaks, Snooze also alerts when a job did not
@@ -56,15 +104,22 @@ extra_rdoc_files:
56
104
  - README.rdoc
57
105
  files:
58
106
  - .gitignore
107
+ - .travis.yml
59
108
  - Gemfile
60
109
  - Gemfile.lock
110
+ - Guardfile
61
111
  - LICENSE
62
112
  - README.rdoc
63
113
  - Rakefile
64
114
  - bin/snooze
65
115
  - lib/snooze.rb
116
+ - lib/snooze/button.rb
117
+ - lib/snooze/connection_error.rb
118
+ - lib/snooze/post.rb
66
119
  - snooze.gemspec
67
120
  - spec/spec_helper.rb
121
+ - spec/unit/button_spec.rb
122
+ - spec/unit/post_spec.rb
68
123
  - tasks/github-gem.rake
69
124
  homepage: http://snooze.io
70
125
  licenses: []
@@ -84,12 +139,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
139
  - - ! '>='
85
140
  - !ruby/object:Gem::Version
86
141
  version: '0'
142
+ segments:
143
+ - 0
144
+ hash: 2415208834990755493
87
145
  required_rubygems_version: !ruby/object:Gem::Requirement
88
146
  none: false
89
147
  requirements:
90
148
  - - ! '>='
91
149
  - !ruby/object:Gem::Version
92
150
  version: '0'
151
+ segments:
152
+ - 0
153
+ hash: 2415208834990755493
93
154
  requirements: []
94
155
  rubyforge_project:
95
156
  rubygems_version: 1.8.24
@@ -97,4 +158,6 @@ signing_key:
97
158
  specification_version: 3
98
159
  summary: A command line tool to inform the webservice at snooze.io that a job has
99
160
  run.
100
- test_files: []
161
+ test_files:
162
+ - spec/unit/button_spec.rb
163
+ - spec/unit/post_spec.rb