rubycron 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,6 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem "mail", ">= 2.4.4"
4
4
 
5
+ gem 'coveralls', require: false
6
+
5
7
  group :test do
6
8
  gem "rspec", "~> 2.0"
7
9
  gem "simplecov", "~> 0.7.1"
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # RubyCron
2
2
 
3
- Define your cronjobs in your favorite language, and get reporting for free!
3
+ **Define your cronjobs in your favorite language, and get reporting for free!**
4
4
 
5
5
  By letting RubyCron deal with warnings, errors, and sending reports, you can focus on writing clean and effective cronjobs in Ruby.
6
6
 
7
+ [![Build Status](https://travis-ci.org/bartkamphorst/rubycron.png?branch=master)](https://travis-ci.org/bartkamphorst/rubycron)
8
+ [![Coverage Status](https://coveralls.io/repos/bartkamphorst/rubycron/badge.png?branch=master)](https://coveralls.io/r/bartkamphorst/rubycron?branch=master)
9
+ [![Gem Version](https://badge.fury.io/rb/rubycron.png)](http://badge.fury.io/rb/rubycron)
10
+
7
11
  ## Author
8
12
 
9
13
  * Bart Kamphorst
@@ -0,0 +1,7 @@
1
+ module RubyCron
2
+ class ExitOnWarning < StandardError
3
+ end
4
+
5
+ class ExitOnError < StandardError
6
+ end
7
+ end
data/lib/rubycron/main.rb CHANGED
@@ -12,9 +12,12 @@ module RubyCron
12
12
  require 'mail'
13
13
  require 'erb'
14
14
 
15
- attr_accessor :name, :author, :mailto, :mailfrom, :mailsubject, :mailon, :exiton, :template, :smtpsettings, :logfile, :verbose
15
+ attr_accessor :name, :author, :mailto, :mailfrom, :mailsubject, :mailon, :exiton, :template, :smtpsettings, :debug, :logfile, :verbose
16
16
  attr_reader :warnings, :errors, :report
17
17
 
18
+ DEFAULT_SERVER = 'localhost'
19
+ DEFAULT_PORT = 25
20
+
18
21
  def initialize(args = nil)
19
22
  @warnings, @errors = [], []
20
23
 
@@ -59,6 +62,7 @@ module RubyCron
59
62
 
60
63
  check_smtp_settings
61
64
  set_defaults
65
+ enable_debug_mode if @debug
62
66
  enable_file_logging if @logfile
63
67
  end
64
68
 
@@ -80,6 +84,11 @@ module RubyCron
80
84
  @exiton = :all unless self.exiton && [:none, :warning, :error, :all].include?(self.exiton)
81
85
  end
82
86
 
87
+ def enable_debug_mode
88
+ @mailon = :none
89
+ @verbose = true
90
+ end
91
+
83
92
  def enable_file_logging
84
93
  $stdout.reopen(@logfile, "a")
85
94
  $stdout.sync = true
@@ -97,39 +106,46 @@ module RubyCron
97
106
  # Execute a given block of code (the cronjob), rescue encountered errors,
98
107
  # and send a report about it if necessary.
99
108
  def execute(&block)
109
+ puts "[INFO ] Running in debug mode. Will not send mail." if self.debug
100
110
  @starttime = Time.now
101
111
  puts "\nStarting run of #{self.name} at #{@starttime}.\n----" if self.verbose || self.logfile
102
112
  instance_eval(&block)
113
+ rescue ExitOnWarning, ExitOnError => e
114
+ terminate(e.message)
103
115
  rescue Exception => e
104
- @errors << e.message
105
- terminate(e.message) if exiton == (:error || :all)
116
+ trace = "#{e.message}\n" + e.backtrace.join("\n\t")
117
+ @errors << trace
118
+ $stderr.puts "[ERROR] #{trace}" if self.verbose || self.logfile
119
+ terminate(trace) if exiton == (:error || :all)
106
120
  ensure
107
121
  @endtime = Time.now
108
- if self.verbose || self.logfile
109
- puts "Run ended at #{@endtime}.\n----"
110
- puts "Number of warnings: #{@warnings.size}"
111
- puts "Number of errors : #{@errors.size}"
112
- end
122
+ produce_summary if (self.verbose || self.logfile)
113
123
  unless self.mailon == :none || (@warnings.empty? && @errors.empty? && self.mailon != :all)
114
124
  send_report
115
125
  end
116
126
  end
117
127
 
128
+ def produce_summary
129
+ puts "Run ended at #{@endtime}.\n----"
130
+ puts "Number of warnings: #{@warnings.size}"
131
+ puts "Number of errors : #{@errors.size}"
132
+ end
133
+
118
134
  def warning(message)
119
- $stderr.puts message if self.verbose || self.logfile
120
- raise "Configured to exit on warning." if exiton == (:warning || :all)
135
+ $stderr.puts "[WARN ] #{message}" if self.verbose || self.logfile
121
136
  @warnings << message
137
+ raise ExitOnWarning.new("Configured to exit on warning.") if exiton == (:warning || :all)
122
138
  end
123
139
 
124
140
  def error(message)
125
- $stderr.puts message if self.verbose || self.logfile
126
- raise "Configured to exit on error." if exiton == (:error || :all)
141
+ $stderr.puts "[ERROR] #{message}" if self.verbose || self.logfile
127
142
  @errors << message
143
+ raise ExitOnError.new("Configured to exit on error.") if exiton == (:error || :all)
128
144
  end
129
145
 
130
146
  private
131
147
  def smtp_connection?
132
- return true if Net::SMTP.start('localhost', 25)
148
+ return true if Net::SMTP.start(DEFAULT_SERVER, DEFAULT_PORT)
133
149
  rescue
134
150
  return false
135
151
  end
@@ -1,3 +1,3 @@
1
1
  module RubyCron
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
data/lib/rubycron.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'rubycron/main'
2
+ require 'rubycron/errors'
2
3
  require 'rubycron/version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-18 00:00:00.000000000 Z
12
+ date: 2013-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mail
@@ -70,13 +70,15 @@ files:
70
70
  - README.md
71
71
  - Gemfile
72
72
  - lib/rubycron.rb
73
+ - lib/rubycron/errors.rb
73
74
  - lib/rubycron/main.rb
74
75
  - lib/rubycron/report.erb
75
76
  - lib/rubycron/version.rb
76
77
  - sample/test.rcj
77
78
  - bin/rcjrunner.rb
78
79
  homepage: https://github.com/bartkamphorst/rubycron
79
- licenses: []
80
+ licenses:
81
+ - Modified BSD
80
82
  post_install_message:
81
83
  rdoc_options: []
82
84
  require_paths:
@@ -95,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
97
  version: '0'
96
98
  requirements: []
97
99
  rubyforge_project:
98
- rubygems_version: 1.8.24
100
+ rubygems_version: 1.8.25
99
101
  signing_key:
100
102
  specification_version: 3
101
103
  summary: Simplifies your Ruby cronjobs by automating the reporting process.