sidekiq-cronitor 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/sidekiq/cronitor/periodic_jobs.rb +14 -0
- data/lib/sidekiq/cronitor/sidekiq_scheduler.rb +21 -0
- data/lib/sidekiq/cronitor/version.rb +1 -1
- data/lib/sidekiq/cronitor.rb +11 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fdd6b7a4900b0b4325bdecbb6774f71748e20d81aa44969b4687e6ee833e4b2
|
4
|
+
data.tar.gz: f61d0a3051c15d95d000273bca3b2f127e70d16a28e2769a19bf976a4e47f088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f687f12236ef9af2041ff33a0ba5df7bdb378ee316ff84ce0c7ae298ab018a973ee168a88eadc07cc4a9d86a3d6ceca9d006a0a166c9f7e4d90462444e70720
|
7
|
+
data.tar.gz: b3d78f111182e36d322c1eaa41f7297b1bddcf286e8240780de2be6092ebd39c36ba9b708b4e013cde8fb8327c751f0a86e73d266951ea4978d5cd72e11c8f34
|
data/README.md
CHANGED
@@ -95,6 +95,23 @@ If you have an entire group or category of jobs you wish to disable monitoring o
|
|
95
95
|
|
96
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
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
|
+
|
98
115
|
## Development
|
99
116
|
|
100
117
|
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.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Sidekiq::Cronitor
|
2
|
+
class PeriodicJobs
|
3
|
+
def self.sync_schedule!
|
4
|
+
monitors_payload = []
|
5
|
+
loops = Sidekiq::Periodic::LoopSet.new
|
6
|
+
loops.each do |lop|
|
7
|
+
job_key = lop.klass.sidekiq_options.fetch("cronitor_key", nil) || lop.klass.to_s
|
8
|
+
cronitor_disabled = lop.klass.sidekiq_options.fetch("cronitor_disabled", false)
|
9
|
+
monitors_payload << {key: job_key, schedule: lop.schedule, metadata: lop.options, platform: 'sidekiq', type: 'job' } unless cronitor_disabled
|
10
|
+
end
|
11
|
+
Cronitor::Monitor.put(monitors: monitors_payload)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sidekiq::Cronitor
|
2
|
+
class SidekiqScheduler
|
3
|
+
def self.sync_schedule!
|
4
|
+
monitors_payload = []
|
5
|
+
# go through the scheduled jobs and find cron defined ones
|
6
|
+
Sidekiq.get_schedule.each do |k, v|
|
7
|
+
# make sure the job has a cron or every definition, we skip non cron/every defined jobs for now
|
8
|
+
if !v["cron"].nil? || !v["every"].nil?
|
9
|
+
schedule = v["cron"] || v["every"]
|
10
|
+
# just in case an explicit job key has been set
|
11
|
+
job_klass = Object.const_get(v["class"])
|
12
|
+
job_key = job_klass.sidekiq_options.fetch("cronitor_key", nil) || v["class"]
|
13
|
+
# if monitoring for this job is turned off
|
14
|
+
cronitor_disabled = job_klass.sidekiq_options.fetch("cronitor_disabled", false)
|
15
|
+
monitors_payload << {key: job_key.to_s, schedule: schedule, platform: 'sidekiq', type: 'job' } unless cronitor_disabled
|
16
|
+
end
|
17
|
+
end
|
18
|
+
Cronitor::Monitor.put(monitors: monitors_payload)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/sidekiq/cronitor.rb
CHANGED
@@ -3,6 +3,14 @@ require 'cronitor'
|
|
3
3
|
|
4
4
|
require 'sidekiq/cronitor/version'
|
5
5
|
|
6
|
+
if defined? SidekiqScheduler
|
7
|
+
require 'sidekiq/cronitor/sidekiq_scheduler'
|
8
|
+
end
|
9
|
+
|
10
|
+
if defined? Sidekiq::Periodic
|
11
|
+
require 'sidekiq/cronitor/periodic_jobs'
|
12
|
+
end
|
13
|
+
|
6
14
|
module Sidekiq::Cronitor
|
7
15
|
class ServerMiddleware
|
8
16
|
def call(worker, message, queue)
|
@@ -24,7 +32,7 @@ module Sidekiq::Cronitor
|
|
24
32
|
end
|
25
33
|
|
26
34
|
def cronitor_disabled?(worker)
|
27
|
-
disabled = worker.class.sidekiq_options.fetch(
|
35
|
+
disabled = worker.class.sidekiq_options.fetch("cronitor_disabled", nil)
|
28
36
|
if disabled.nil?
|
29
37
|
options(worker).fetch(:disabled, false)
|
30
38
|
else
|
@@ -33,14 +41,14 @@ module Sidekiq::Cronitor
|
|
33
41
|
end
|
34
42
|
|
35
43
|
def job_key(worker)
|
36
|
-
worker.class.sidekiq_options.fetch(
|
44
|
+
worker.class.sidekiq_options.fetch("cronitor_key", nil) ||
|
37
45
|
options(worker).fetch(:key, worker.class.name)
|
38
46
|
end
|
39
47
|
|
40
48
|
def options(worker)
|
41
49
|
# eventually we will delete this method of passing options
|
42
50
|
# ultimately we want all cronitor options to be top level keys
|
43
|
-
opts = worker.class.sidekiq_options.fetch(
|
51
|
+
opts = worker.class.sidekiq_options.fetch("cronitor", {})
|
44
52
|
# symbolize_keys is a rails helper, so only use it if it's defined
|
45
53
|
opts = opts.symbolize_keys if opts.respond_to?(:symbolize_keys)
|
46
54
|
opts
|
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.1.
|
4
|
+
version: 3.1.1
|
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-04-
|
12
|
+
date: 2022-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|
@@ -107,6 +107,8 @@ files:
|
|
107
107
|
- LICENSE
|
108
108
|
- README.md
|
109
109
|
- lib/sidekiq/cronitor.rb
|
110
|
+
- lib/sidekiq/cronitor/periodic_jobs.rb
|
111
|
+
- lib/sidekiq/cronitor/sidekiq_scheduler.rb
|
110
112
|
- lib/sidekiq/cronitor/version.rb
|
111
113
|
homepage: https://github.com/cronitor/sidekiq-cronitor
|
112
114
|
licenses:
|