sidekiq-cronitor 1.0.0.alpha
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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/LICENSE +21 -0
- data/README.md +106 -0
- data/lib/sidekiq/cronitor.rb +111 -0
- data/lib/sidekiq/cronitor/version.rb +5 -0
- metadata +138 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a9be623c484eb06cd00eb0c7687351252266e2f5
|
4
|
+
data.tar.gz: 473caa08118deaae2c4ff3985fdfe31fb59ad2f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66712be66af8fab84b8a41763f806bc411278841a984996e91e23cd841fdb2adcc2f49841ec1dc4417dfc9a9edffa602304fbbfdc04ffa27407c53b51cc8d714
|
7
|
+
data.tar.gz: c3f8671045720143dc77b8e686bafe12a5af8705969319a5f3181b3c8ab09f500c9883ec935ed13ce812ca19f579efce71bca028277b858308c3aadf8de3840e
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
Binary file
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Samuel Cochran
|
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,106 @@
|
|
1
|
+
# Sidekiq Cronitor
|
2
|
+
|
3
|
+
Call a [Cronitor](https://cronitor.io) around your [Sidekiq](https://sidekiq.org) jobs.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add sidekiq-cronitor your application's Gemfile, near sidekiq:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "sidekiq"
|
11
|
+
gem "sidekiq-cronitor"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then bundle:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Make sure you've got a Cronitor [API Key](https://cronitor.io/docs/api-overview) from [your settings](https://cronitor.io/settings) in your ENV as `$CRONITOR_TOKEN` before starting Sidekiq:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
export CRONITOR_TOKEN="abcdef1234567890abcdef1234567890"
|
24
|
+
sidekiq
|
25
|
+
```
|
26
|
+
|
27
|
+
Any sidekiq worker you'd like to monitor just includes `Sidekiq::Cronitor` right after `Sidekiq::Worker`:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class MyWorker
|
31
|
+
include Sidekiq::Worker
|
32
|
+
include Sidekiq::Cronitor
|
33
|
+
|
34
|
+
def perform
|
35
|
+
# ...
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
By default this will look for an existing monitor named after your worker, `MyWorker` in the case above, and pings that. Otherwise it will try to create a new monitor with the name.
|
41
|
+
|
42
|
+
To use a monitor you've already created you can also configure a code directly:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class MyWorker
|
46
|
+
include Sidekiq::Worker
|
47
|
+
include Sidekiq::Cronitor
|
48
|
+
|
49
|
+
sidekiq_options cronitor: {code: "abc123"}
|
50
|
+
|
51
|
+
def perform
|
52
|
+
# ...
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
To use a different name or customise how a missing monitor will be created you can use a sidekiq option named `cronitor`:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
class MyWorker
|
61
|
+
include Sidekiq::Worker
|
62
|
+
include Sidekiq::Cronitor
|
63
|
+
|
64
|
+
sidekiq_options cronitor: {
|
65
|
+
name: "Some Monitor",
|
66
|
+
rules: [{rule_type: "ran_longer_than", value: 60, time_unit: "seconds"}]
|
67
|
+
}
|
68
|
+
|
69
|
+
def perform
|
70
|
+
# ...
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
For more information on what rules you can use take a look at the [Cronitor Monitors API docs](https://cronitor.io/docs/monitor-api).
|
76
|
+
|
77
|
+
If you're using [sidekiq-cron](https://github.com/ondrejbartas/sidekiq-cron) the missing monitor will have a default `not_on_schedule` rule based on the cron schedule matched by you worker class.
|
78
|
+
|
79
|
+
You can also just supply a Cronitor instance to use directly:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class MyWorker
|
83
|
+
include Sidekiq::Worker
|
84
|
+
include Sidekiq::Cronitor
|
85
|
+
|
86
|
+
sidekiq_options cronitor: Cronitor.new(...)
|
87
|
+
|
88
|
+
def perform
|
89
|
+
# ...
|
90
|
+
end
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
## Development
|
95
|
+
|
96
|
+
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.
|
97
|
+
|
98
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sj26/sidekiq-cronitor. 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.
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "sidekiq"
|
2
|
+
require "cronitor"
|
3
|
+
|
4
|
+
require "sidekiq/cronitor/version"
|
5
|
+
|
6
|
+
module Sidekiq::Cronitor
|
7
|
+
def self.included(base)
|
8
|
+
unless base.ancestors.include? Sidekiq::Worker
|
9
|
+
raise ArgumentError, "Sidekiq::Cronitor can only be included in a Sidekiq::Worker"
|
10
|
+
end
|
11
|
+
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
|
14
|
+
# Automatically add sidekiq middleware when we're first included
|
15
|
+
#
|
16
|
+
# This might only occur when the worker class is first loaded in a
|
17
|
+
# development rails environment, but that happens before the middleware
|
18
|
+
# chain is invoked so we're all good.
|
19
|
+
#
|
20
|
+
Sidekiq.configure_server do |config|
|
21
|
+
unless config.server_middleware.exists? Sidekiq::Cronitor::Middleware
|
22
|
+
config.server_middleware.add Sidekiq::Cronitor::Middleware
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def cronitor
|
28
|
+
self.class.cronitor
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
def cronitor
|
33
|
+
return @cronitor if defined? @cronitor
|
34
|
+
|
35
|
+
# Sidekiq always stores options as string keys, shallowly at least
|
36
|
+
opts = sidekiq_options.fetch("cronitor", {})
|
37
|
+
|
38
|
+
if opts.is_a? Cronitor
|
39
|
+
return @cronitor = opts
|
40
|
+
end
|
41
|
+
|
42
|
+
# Cronitor (and our code below) expects deeply symbolized keys
|
43
|
+
opts = Utils.deep_symbolize_keys(opts)
|
44
|
+
|
45
|
+
# Extract token and code into top level kwargs
|
46
|
+
kwargs = opts.slice(:token, :code).merge(opts: opts)
|
47
|
+
|
48
|
+
# Default monitor name to sidekiq worker (class) name
|
49
|
+
kwargs[:opts][:name] ||= name
|
50
|
+
|
51
|
+
# If we're using Sidekiq::Cron and there's a job for this class then use
|
52
|
+
# it's cron schedule for a default not_on_schedudle rule, and tag this as
|
53
|
+
# a cron job
|
54
|
+
if defined?(Sidekiq::Cron) && job = Sidekiq::Cron::Job.all.find { |j| j.klass == name }
|
55
|
+
kwargs[:opts][:rules] ||= [{rule_type: "not_on_schedule", value: job.cron}]
|
56
|
+
kwargs[:opts][:tags] ||= ["cron-job", "sidekiq-cron", "sidekiq-cronitor"]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Some hints about where this monitor came from
|
60
|
+
kwargs[:opts][:tags] ||= ["sidekiq-cronitor"]
|
61
|
+
kwargs[:opts][:note] ||= "Created by sidekiq-cronitor"
|
62
|
+
|
63
|
+
begin
|
64
|
+
@cronitor = Cronitor.new(**kwargs)
|
65
|
+
rescue Cronitor::Error => e
|
66
|
+
Sidekiq.logger.warn "Couldn't initialize Cronitor: #{e.to_s}"
|
67
|
+
|
68
|
+
@cronitor = nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Middleware
|
74
|
+
def call(worker, message, queue)
|
75
|
+
begin
|
76
|
+
ping worker, "run"
|
77
|
+
|
78
|
+
yield
|
79
|
+
rescue => e
|
80
|
+
ping worker, "failed", e.to_s
|
81
|
+
|
82
|
+
raise
|
83
|
+
else
|
84
|
+
ping worker, "complete"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def ping(worker, type, msg=nil)
|
91
|
+
if cronitor? worker
|
92
|
+
Sidekiq.logger.debug "Cronitor ping: #{type}"
|
93
|
+
worker.cronitor.ping(type)
|
94
|
+
end
|
95
|
+
rescue Cronitor::Error => e
|
96
|
+
Sidekiq.logger.warn "Couldn't ping Cronitor: #{e.to_s}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def cronitor? worker
|
100
|
+
worker.is_a?(Sidekiq::Cronitor) && worker.cronitor
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
module Utils
|
105
|
+
def self.deep_symbolize_keys(hash) #+nodoc+
|
106
|
+
hash.each_with_object({}) do |(key, value), new_hash|
|
107
|
+
new_hash[key.to_sym] = value.is_a?(Hash) ? deep_symbolize_keys(value) : value
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sidekiq-cronitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Cochran
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDKDCCAhCgAwIBAgIBBTANBgkqhkiG9w0BAQUFADA6MQ0wCwYDVQQDDARzajI2
|
14
|
+
MRQwEgYKCZImiZPyLGQBGRYEc2oyNjETMBEGCgmSJomT8ixkARkWA2NvbTAeFw0x
|
15
|
+
NzA3MzEwNTQ3MDVaFw0xODA3MzEwNTQ3MDVaMDoxDTALBgNVBAMMBHNqMjYxFDAS
|
16
|
+
BgoJkiaJk/IsZAEZFgRzajI2MRMwEQYKCZImiZPyLGQBGRYDY29tMIIBIjANBgkq
|
17
|
+
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsr60Eo/ttCk8GMTMFiPr3GoYMIMFvLak
|
18
|
+
xSmTk9YGCB6UiEePB4THSSA5w6IPyeaCF/nWkDp3/BAam0eZMWG1IzYQB23TqIM0
|
19
|
+
1xzcNRvFsn0aQoQ00k+sj+G83j3T5OOV5OZIlu8xAChMkQmiPd1NXc6uFv+Iacz7
|
20
|
+
kj+CMsI9YUFdNoU09QY0b+u+Rb6wDYdpyvN60YC30h0h1MeYbvYZJx/iZK4XY5zu
|
21
|
+
4O/FL2ChjL2CPCpLZW55ShYyrzphWJwLOJe+FJ/ZBl6YXwrzQM9HKnt4titSNvyU
|
22
|
+
KzE3L63A3PZvExzLrN9u09kuWLLJfXB2sGOlw3n9t72rJiuBr3/OQQIDAQABozkw
|
23
|
+
NzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU99dfRjEKFyczTeIz
|
24
|
+
m3ZsDWrNC80wDQYJKoZIhvcNAQEFBQADggEBADGiXpvK754s0zTFx3y31ZRDdvAI
|
25
|
+
lA209JIjUlDyr9ptCRadihyfF2l9/hb+hLemiPEYppzG6vEK1TIyzbAR36yOJ8CX
|
26
|
+
4vPkCXLuwHhs6UIRbwN+IEy41nsIlBxmjLYei8h3t/G2Vm2oOaLdbjDXS+Srl9U8
|
27
|
+
shsE8ft81PxSQfzEL7Mr9cC9XvWbHW+SyTpfGm8rAtaqZkNeke4U8a0di4oz2EfA
|
28
|
+
P4lSfmXxsd1C71ckIp0cyXkPhyTtpyS/5hq9HhuUNzEHkSDe36/Rd1xYKV5JxMC2
|
29
|
+
YAttWFUs06lor2q1wwncPaMtUtbWwW35+1IV6xhs2rFY6DD/I6ZkK3GnHdY=
|
30
|
+
-----END CERTIFICATE-----
|
31
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
32
|
+
dependencies:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sidekiq
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '5.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: cronitor
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.16'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.16'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '10.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '10.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.0'
|
103
|
+
description: Integrates sidekiq with cronitor so that workers call run/complete/failed
|
104
|
+
around their perform methods
|
105
|
+
email: sj26@sj26.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- LICENSE
|
111
|
+
- README.md
|
112
|
+
- lib/sidekiq/cronitor.rb
|
113
|
+
- lib/sidekiq/cronitor/version.rb
|
114
|
+
homepage: https://github.com/sj26/sidekiq-cronitor
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.3.1
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.6.14
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Monitor your sidekiq jobs with Cronitor
|
138
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|