cronitor_activejob 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 49e937011714253f7762a40b12cb845b005520d3d6ba173b3b3d8dfb62b3e6c2
4
+ data.tar.gz: 1e3ab688e21e39e11e347e5194a3e5bae7ac6960f22bd91108635596e53d13ed
5
+ SHA512:
6
+ metadata.gz: 124158d81dde7d3c92675e41db8c2887944b50beca29ea81bf8388c0a6fde4eabb3d225976103c1f02a8186aa8d381e08ea69dd9c59c5a322c528b88dea9d11d
7
+ data.tar.gz: 95e6317e961bde10cee6f29f95b0a66296c69554bba6b5460cc8de8f3eff048bc1a93e11524f3ae7429fbda4b8e63baedd3c4dd1a85174f0dea22adbeb24df35
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Kevin Tom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Cronitor::ActiveJob
2
+
3
+ [Cronitor](https://cronitor.io/) provides dead simple monitoring for cron jobs, daemons, queue workers, websites, APIs, and anything else that can send or receive an HTTP request. The Cronitor ActiveJob library provides a drop in integration for monitoring any ActiveJob job.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cronitor_activejob'
11
+ ```
12
+
13
+ And then bundle:
14
+
15
+ $ bundle
16
+
17
+
18
+ ## Usage
19
+
20
+ Configure `cronitor` with an [API Key](https://cronitor.io/docs/api-overview) from [your settings](https://cronitor.io/settings). You can use ENV variables to configure Cronitor:
21
+
22
+ ```sh
23
+ export CRONITOR_API_KEY='api_key_123'
24
+ export CRONITOR_ENVIRONMENT='development' #default: 'production'
25
+ ```
26
+
27
+ Or declare the API key directly on the Cronitor module from within your application (e.g. with an initializer).
28
+
29
+ ```ruby
30
+ require 'cronitor'
31
+ Cronitor.api_key = 'api_key_123'
32
+ Cronitor.environment = 'development' #default: 'production'
33
+ ```
34
+
35
+
36
+ To monitor jobs include the module in your job class
37
+
38
+ ```ruby
39
+ class MyJob < ApplicationJob
40
+ include Cronitor::ActiveJob
41
+ end
42
+ ```
43
+
44
+ When this job is invoked, Cronitor will send telemetry pings with a `key` matching the name of your job class (`MyJob` in the example above). If no monitor exists it will create one on the first event. You can configure rules at a later time via the Cronitor dashboard, API, or [YAML config](https://github.com/cronitorio/cronitor-ruby#configuring-monitors) file.
45
+
46
+ Optional: You can specify the monitor key directly using `cronitor_key`:
47
+
48
+ ```ruby
49
+ class MyJob < ApplicationJob
50
+ include Cronitor::ActiveJob
51
+ cronitor_key 'abc123'
52
+
53
+ def perform
54
+ end
55
+ end
56
+ ```
57
+
58
+
59
+ To disable Cronitor for a specific job you can set the following option:
60
+
61
+ ```ruby
62
+ class MyJob < ApplicationJob
63
+ include Cronitor::ActiveJob
64
+ cronitor_disabled: true
65
+
66
+ def perform
67
+ end
68
+ end
69
+ ```
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cronitorio/cronitor-activejob. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cronitor
4
+ module ActiveJob
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "active_job/version"
4
+ require "cronitor"
5
+
6
+ module Cronitor
7
+ # Notify Cronitor of ActiveJob progress around perform
8
+ module ActiveJob
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ around_perform :cronitor_instrumentation
13
+
14
+ def self.cronitor_disabled(disabled)
15
+ @cronitor_disabled = !!disabled
16
+ end
17
+
18
+ def self.cronitor_disabled?
19
+ @cronitor_disabled || false
20
+ end
21
+
22
+ def self.cronitor_key(key)
23
+ @cronitor_key = key
24
+ end
25
+
26
+ def self.cronitor_job_key
27
+ @cronitor_key || name
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def cronitor_instrumentation(&block)
34
+ if should_ping?
35
+ Cronitor.job(self.class.cronitor_job_key, &block)
36
+ else
37
+ yield
38
+ end
39
+ end
40
+
41
+ def should_ping?
42
+ Cronitor.api_key.present? && !self.class.cronitor_disabled?
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cronitor/active_job"
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cronitor_activejob
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Tom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cronitor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activejob
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Instrument ActiveJob jobs with Cronitor to monitor lifecycle events around
56
+ the perform method.
57
+ email:
58
+ - kevintom@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ - lib/cronitor/active_job.rb
66
+ - lib/cronitor/active_job/version.rb
67
+ - lib/cronitor_activejob.rb
68
+ homepage: https://github.com/cronitor/cronitor-activejob
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.6.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.1.4
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: ActiveJob integration with Cronitor.
91
+ test_files: []