sidekiq-cronitor 3.1.1 → 3.3.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 +4 -4
- data/README.md +7 -32
- data/lib/sidekiq/cronitor/periodic_jobs.rb +9 -3
- data/lib/sidekiq/cronitor/sidekiq_scheduler.rb +14 -10
- data/lib/sidekiq/cronitor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceb0fb42649e7e03c7f125204eb12a315225acbf731d35e6c850e1a12730c6c9
|
4
|
+
data.tar.gz: 5534007db95190d63581020952e22a0f227231ac7917bbda63bcbdf619b4df8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4542db6ff37a9b265b11a7b5e7197ea90502d2e1db8f4e71624ad155f5895456e10bf454688e544a4aa098e1d52f7df78fbde4b236d2656b6f13a5b07c127fd8
|
7
|
+
data.tar.gz: 35ec24c9f75bf7f69e5da4d4150377c5d8e9dcaf2e6aaed571b4199787df3b46af3e196611de4eae23d241fa3eeaaa06d0754a6199749d1174bdc61297b229b5
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ Cronitor.environment = 'development' #default: 'production'
|
|
40
40
|
```
|
41
41
|
|
42
42
|
|
43
|
-
|
43
|
+
Monitor jobs by registering `Sidekiq::Cronitor::ServerMiddleware` server [middleware](https://www.rubydoc.info/github/mperham/sidekiq/Sidekiq/Middleware) (most people do this in the Sidekiq initializer).
|
44
44
|
|
45
45
|
```ruby
|
46
46
|
Sidekiq.configure_server do |config|
|
@@ -51,7 +51,7 @@ end
|
|
51
51
|
```
|
52
52
|
|
53
53
|
|
54
|
-
|
54
|
+
Once the server middleware is registered, Cronitor will send [telemetry events](https://cronitor.io/docs/teleme) with a `key` matching the name of your job class (`MyJob` in the example below). 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.
|
55
55
|
|
56
56
|
Optional: You can specify the monitor key directly using `sidekiq_options`:
|
57
57
|
|
@@ -65,7 +65,6 @@ class MyJob
|
|
65
65
|
end
|
66
66
|
```
|
67
67
|
|
68
|
-
|
69
68
|
To disable Cronitor for a specific job you can set the following option:
|
70
69
|
|
71
70
|
```ruby
|
@@ -78,39 +77,15 @@ class MyJob
|
|
78
77
|
end
|
79
78
|
```
|
80
79
|
|
81
|
-
##
|
82
|
-
If you
|
80
|
+
## Periodic/Scheduled Jobs
|
81
|
+
If you are using Sidekiq Enterprise to run [Periodic Jobs](https://github.com/mperham/sidekiq/wiki/Ent-Periodic-Jobs) or are using the popular [sidekiq-scheduler](https://github.com/moove-it/sidekiq-scheduler) gem, you can sync the schedules of those jobs with a single command.
|
83
82
|
|
84
83
|
```ruby
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
class NoInstrumentationJob < UnmonitoredJob
|
91
|
-
def perform
|
92
|
-
end
|
93
|
-
end
|
84
|
+
Sidekiq::Cronitor::PeriodicJobs.sync_schedule!
|
85
|
+
# or
|
86
|
+
Sidekiq::Cronitor::SidekiqScheduler.sync_schedule!
|
94
87
|
```
|
95
88
|
|
96
|
-
Note: Do NOT set a cronitor_key option on your base class or all your inherited jobs will report under the same job in Cronitor.
|
97
|
-
|
98
|
-
## Job Monitoring
|
99
|
-
If you are using Cronitor to monitor scheduled/periodic jobs and have jobs schedules already defined you can use rake tasks to upload the schedule to Cronitor for monitoring.
|
100
|
-
|
101
|
-
In your projects Rakefile you can load the task to be available to you in your project.
|
102
|
-
It might be a good idea to sync these schedules on every deploy
|
103
|
-
|
104
|
-
```ruby
|
105
|
-
# your Rakefile, find the path to the gem
|
106
|
-
spec = Gem::Specification.find_by_name 'sidekiq-cronitor'
|
107
|
-
# if you are using sidekiq_scheduler this task should parse and upload the schedule.
|
108
|
-
load "#{spec.gem_dir}/lib/tasks/sidekiq_scheduler.rake"
|
109
|
-
# if you are using Sidekiq Pro Periodic Jobs this is an example script
|
110
|
-
# Note: this hasn't been tested on Sidekiq Pro yet
|
111
|
-
load "#{spec.gem_dir}/lib/tasks/periodic_jobs.rake"
|
112
|
-
# You only really need to load one of the rake files unless you are somehow running both systems
|
113
|
-
```
|
114
89
|
|
115
90
|
## Development
|
116
91
|
|
@@ -1,14 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sidekiq::Cronitor
|
2
4
|
class PeriodicJobs
|
3
5
|
def self.sync_schedule!
|
4
6
|
monitors_payload = []
|
5
7
|
loops = Sidekiq::Periodic::LoopSet.new
|
6
8
|
loops.each do |lop|
|
7
|
-
job_key = lop.klass.sidekiq_options.fetch(
|
8
|
-
|
9
|
-
|
9
|
+
job_key = lop.klass.sidekiq_options.fetch('cronitor_key', lop.klass.to_s)
|
10
|
+
next if lop.klass.sidekiq_options.fetch('cronitor_disabled', false)
|
11
|
+
|
12
|
+
monitors_payload << { key: job_key, schedule: lop.schedule, metadata: lop.options, platform: 'sidekiq', type: 'job' }
|
10
13
|
end
|
14
|
+
|
11
15
|
Cronitor::Monitor.put(monitors: monitors_payload)
|
16
|
+
rescue Cronitor::Error => e
|
17
|
+
Sidekiq.logger.error("[cronitor] error during #{name}.#{__method__}: #{e}")
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
@@ -1,21 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sidekiq::Cronitor
|
2
4
|
class SidekiqScheduler
|
3
5
|
def self.sync_schedule!
|
4
6
|
monitors_payload = []
|
5
7
|
# go through the scheduled jobs and find cron defined ones
|
6
|
-
Sidekiq.get_schedule.each do |
|
8
|
+
Sidekiq.get_schedule.each do |_k, v|
|
7
9
|
# make sure the job has a cron or every definition, we skip non cron/every defined jobs for now
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
10
|
+
next unless (schedule = v['cron'] || v['every'])
|
11
|
+
|
12
|
+
# just in case an explicit job key has been set
|
13
|
+
job_klass = Object.const_get(v['class'])
|
14
|
+
job_key = job_klass.sidekiq_options.fetch('cronitor_key', v['class'])
|
15
|
+
next if job_klass.sidekiq_options.fetch('cronitor_disabled', false)
|
16
|
+
|
17
|
+
monitors_payload << { key: job_key.to_s, schedule: schedule, platform: 'sidekiq', type: 'job' }
|
17
18
|
end
|
19
|
+
|
18
20
|
Cronitor::Monitor.put(monitors: monitors_payload)
|
21
|
+
rescue Cronitor::Error => e
|
22
|
+
Sidekiq.logger.error("[cronitor] error during #{name}.#{__method__}: #{e}")
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-cronitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeke Gabrielse
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|