checker_jobs 1.0.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dff9e8e2b91b729928d02a856b2a1848afe909ed2c17a5ba39cded6f992e8087
4
- data.tar.gz: 11ae8c80cb23614057e45fbdb70de548cb7dac6e9e3368564a586a0d247272e9
3
+ metadata.gz: 8d3774f5e1476ee67df067f568c61988441280eb40d0a59a14e13210a967d058
4
+ data.tar.gz: aab870d45b4ed42e342c212cd86a0ac014481fb47ac93b32af34bec45cd9c99a
5
5
  SHA512:
6
- metadata.gz: bf7ed95487af7d2d5df3a8c884d17a66fa90fef168a7c7c72b6551a595ae12c46765024117e54b02e821aadc0d1b0c79a566ff45472a4dc97181b7b503f0f0c4
7
- data.tar.gz: 6754adfa0d2849ee8cabecd9e379489908f85d2a6bf349dbba75d3513645a0269f8f7e5848d375a4854b5fd93cd3b50c05c5e137d93a470099f9b4dd6a1dd02c
6
+ metadata.gz: bd703fda86b95bd18867ce82c7dbf07b02e428c653d4fbe0b5ad30f4ba88cdc38bfa37db8442a88c69350c4ed8956c2422e83c010a91443bc4efaba69eabdcb9
7
+ data.tar.gz: 242abd0c1a768fd377026bb48327b5ab2be23280266e45ec7c5d9bda8792627cc491fed7c3acb4f00d34fad3832893c14bd5e4690c5ef831b14152583ec1c455
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- checker_jobs (1.0.0)
4
+ checker_jobs (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -36,6 +36,7 @@ GEM
36
36
  addressable (2.5.2)
37
37
  public_suffix (>= 2.0.2, < 4.0)
38
38
  ast (2.4.0)
39
+ bugsnag (5.4.1)
39
40
  builder (3.2.3)
40
41
  byebug (9.1.0)
41
42
  coderay (1.1.2)
@@ -190,6 +191,7 @@ PLATFORMS
190
191
 
191
192
  DEPENDENCIES
192
193
  actionmailer (~> 5.0)
194
+ bugsnag
193
195
  bundler (~> 1.13)
194
196
  checker_jobs!
195
197
  mailcatcher
data/README.md CHANGED
@@ -119,6 +119,7 @@ PRs are appreciated 🙏
119
119
 
120
120
  We support different kind of notifiers, as of today we have the following:
121
121
 
122
+ - `:bugsnag`: uses `Bugsnag` to send notifications. It takes the global configuration.
122
123
  - `:email`: uses `ActionMailer` to send emails. You can pass it any `ActionMailer` options.
123
124
  - `:logger`: Uses `Logger` to output inconsitencies in the log. Takes the following params:
124
125
  - `logdev`: The log device. This is a filename (String) or IO object (typically STDOUT, STDERR, or an open file).
data/checker_jobs.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_development_dependency "actionmailer", "~> 5.0"
24
+ spec.add_development_dependency "bugsnag"
24
25
  spec.add_development_dependency "bundler", "~> 1.13"
25
26
  spec.add_development_dependency "mailcatcher"
26
27
  spec.add_development_dependency "pronto"
@@ -1,12 +1,13 @@
1
- require "checker_jobs/emails_backends"
1
+ require "checker_jobs/notifiers"
2
2
  require "checker_jobs/jobs_processors"
3
3
 
4
4
  class CheckerJobs::Configuration
5
5
  DEFAULT_TIME_BETWEEN_CHECKS = 15 * 60 # 15 minutes, expressed in seconds
6
6
 
7
7
  NOTIFIER_CLASSES = {
8
- email: "CheckerJobs::Notifiers::Email",
9
- logger: "CheckerJobs::Notifiers::Logger",
8
+ email: "CheckerJobs::Notifiers::Email",
9
+ logger: "CheckerJobs::Notifiers::Logger",
10
+ bugsnag: "CheckerJobs::Notifiers::Bugsnag",
10
11
  }.freeze
11
12
 
12
13
  attr_accessor :jobs_processor,
@@ -1,5 +1,7 @@
1
1
  module CheckerJobs::Notifiers
2
+ autoload :Bugsnag, "checker_jobs/notifiers/bugsnag"
2
3
  autoload :Email, "checker_jobs/notifiers/email"
3
4
  autoload :EmailDefaultFormatter, "checker_jobs/notifiers/email_default_formatter"
5
+ autoload :FormatterHelpers, "checker_jobs/notifiers/formatter_helpers"
4
6
  autoload :Logger, "checker_jobs/notifiers/logger"
5
7
  end
@@ -0,0 +1,26 @@
1
+ require "action_mailer"
2
+
3
+ class CheckerJobs::Notifiers::Bugsnag
4
+ include CheckerJobs::Notifiers::FormatterHelpers
5
+
6
+ class Error < StandardError; end
7
+
8
+ def initialize(check, count, entries)
9
+ @check = check
10
+ @metadata = {
11
+ klass: @check.klass,
12
+ name: @check.name,
13
+ count: count,
14
+ entries: entries,
15
+ }
16
+ end
17
+
18
+ def notify
19
+ raise Error, "(#{@check.klass}) #{human_check_name} was triggered!"
20
+ rescue Error => error
21
+ ::Bugsnag.notify(error, {
22
+ severity: "warning",
23
+ triggered_check: @metadata,
24
+ })
25
+ end
26
+ end
@@ -1,4 +1,6 @@
1
1
  class CheckerJobs::Notifiers::EmailDefaultFormatter
2
+ include CheckerJobs::Notifiers::FormatterHelpers
3
+
2
4
  def initialize(check, count, entries)
3
5
  @check = check
4
6
  @count = count
@@ -6,8 +8,7 @@ class CheckerJobs::Notifiers::EmailDefaultFormatter
6
8
  end
7
9
 
8
10
  def subject
9
- name = @check.name.tr("_", " ").capitalize
10
- "#{name} checker found #{@count} element(s)"
11
+ "#{human_check_name} checker found #{@count} element(s)"
11
12
  end
12
13
 
13
14
  def body
@@ -23,32 +24,8 @@ class CheckerJobs::Notifiers::EmailDefaultFormatter
23
24
 
24
25
  private
25
26
 
26
- GITHUB_URL_FORMAT = "https://github.com/%<repository>s/blob/master/%<path>s#L%<line>i".freeze
27
-
28
- def repository_url
29
- if repository_configuration.is_a?(String)
30
- repository_configuration
31
- elsif repository_configuration.key?(:github)
32
- github_url
33
- end
34
- end
35
-
36
- def github_url
37
- filepath, line_number = @check.block.source_location
38
- filepath = filepath.sub(Dir.pwd + "/", "")
39
- GITHUB_URL_FORMAT % {
40
- repository: repository_configuration[:github],
41
- path: filepath,
42
- line: line_number,
43
- }
44
- end
45
-
46
27
  def format_entry(entry)
47
28
  # NOTE: inherit and override to support your custom objects
48
29
  entry.respond_to?(:id) ? entry.id : entry
49
30
  end
50
-
51
- def repository_configuration
52
- CheckerJobs.configuration.repository_url
53
- end
54
31
  end
@@ -0,0 +1,34 @@
1
+ # Needs a @check instance variable and provides the methods:
2
+ # - #repository_url
3
+ # - #human_check_name
4
+ module CheckerJobs::Notifiers::FormatterHelpers
5
+ GITHUB_URL_FORMAT = "https://github.com/%<repository>s/blob/master/%<path>s#L%<line>i".freeze
6
+
7
+ def human_check_name
8
+ @check.name.tr("_", " ").capitalize
9
+ end
10
+
11
+ def repository_url
12
+ if repository_configuration.is_a?(String)
13
+ repository_configuration
14
+ elsif repository_configuration.key?(:github)
15
+ github_url
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def github_url
22
+ filepath, line_number = @check.block.source_location
23
+ filepath = filepath.sub(Dir.pwd + "/", "")
24
+ GITHUB_URL_FORMAT % {
25
+ repository: repository_configuration[:github],
26
+ path: filepath,
27
+ line: line_number,
28
+ }
29
+ end
30
+
31
+ def repository_configuration
32
+ CheckerJobs.configuration.repository_url
33
+ end
34
+ end
@@ -1,6 +1,8 @@
1
1
  require "logger"
2
2
 
3
3
  class CheckerJobs::Notifiers::Logger
4
+ include CheckerJobs::Notifiers::FormatterHelpers
5
+
4
6
  DEFAULT_LEVEL = Logger::INFO
5
7
  DEFAULT_LOGDEV = STDOUT
6
8
 
@@ -15,7 +17,7 @@ class CheckerJobs::Notifiers::Logger
15
17
  end
16
18
 
17
19
  def notify
18
- @logger.add(level, format, @check.name.tr("_", " ").capitalize)
20
+ @logger.add(level, format, human_check_name)
19
21
  end
20
22
 
21
23
  # override this
@@ -1,3 +1,3 @@
1
1
  module CheckerJobs
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checker_jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drivy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-07-31 00:00:00.000000000 Z
12
+ date: 2018-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionmailer
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '5.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bugsnag
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: bundler
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -209,12 +223,14 @@ files:
209
223
  - lib/checker_jobs/checks/ensure_no.rb
210
224
  - lib/checker_jobs/configuration.rb
211
225
  - lib/checker_jobs/dsl.rb
212
- - lib/checker_jobs/emails_backends.rb
213
226
  - lib/checker_jobs/errors.rb
214
227
  - lib/checker_jobs/jobs_processors.rb
215
228
  - lib/checker_jobs/jobs_processors/sidekiq.rb
229
+ - lib/checker_jobs/notifiers.rb
230
+ - lib/checker_jobs/notifiers/bugsnag.rb
216
231
  - lib/checker_jobs/notifiers/email.rb
217
232
  - lib/checker_jobs/notifiers/email_default_formatter.rb
233
+ - lib/checker_jobs/notifiers/formatter_helpers.rb
218
234
  - lib/checker_jobs/notifiers/logger.rb
219
235
  - lib/checker_jobs/version.rb
220
236
  homepage: https://github.com/drivy/checker_jobs