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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fdd6b7a4900b0b4325bdecbb6774f71748e20d81aa44969b4687e6ee833e4b2
4
- data.tar.gz: f61d0a3051c15d95d000273bca3b2f127e70d16a28e2769a19bf976a4e47f088
3
+ metadata.gz: ceb0fb42649e7e03c7f125204eb12a315225acbf731d35e6c850e1a12730c6c9
4
+ data.tar.gz: 5534007db95190d63581020952e22a0f227231ac7917bbda63bcbdf619b4df8e
5
5
  SHA512:
6
- metadata.gz: 1f687f12236ef9af2041ff33a0ba5df7bdb378ee316ff84ce0c7ae298ab018a973ee168a88eadc07cc4a9d86a3d6ceca9d006a0a166c9f7e4d90462444e70720
7
- data.tar.gz: b3d78f111182e36d322c1eaa41f7297b1bddcf286e8240780de2be6092ebd39c36ba9b708b4e013cde8fb8327c751f0a86e73d266951ea4978d5cd72e11c8f34
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
- To monitor jobs insert the server middleware (most people do this in the Sidekiq initializer)
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
- When this job is invoked, Cronitor will send telemetry pings 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.
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
- ## Disabling For Some Jobs
82
- If you have an entire group or category of jobs you wish to disable monitoring on, it's easiest to create a base class with that option set and then have all your jobs inherit from that base class.
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
- class UnmonitoredJob
86
- include Sidekiq::Job
87
- sidekiq_options cronitor_disabled: true
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("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
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 |k, v|
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
- 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
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
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Cronitor
3
- VERSION = '3.1.1'
3
+ VERSION = '3.3.0'
4
4
  end
5
5
  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.1.1
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-04-20 00:00:00.000000000 Z
12
+ date: 2022-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq