sidekiq-cronitor 3.1.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 826cb62a159a1c7f33af2cdabe5f56edfb2debaef6d73f9541f61106a8f77e0a
4
- data.tar.gz: e459ad13e7723388db7c4448c192edb426de1454a2b22a28ec3441917bc17fdc
3
+ metadata.gz: ebea71b4352db386aa8712eb8462b88b4f2a91ed0e7921face88453eb56981e7
4
+ data.tar.gz: 74fd0296d97a9480d55442d777937c6ae21f6a0821b6c690c8f9d366432ad998
5
5
  SHA512:
6
- metadata.gz: b3f6e392551e1118f5db63a7057fa61b4aa0efb060fa9eb2b598f8afc6ad5c268e68c614dad8dfbf168b128a2139fae26fc6e5835754826f35dd6ea361c9e50a
7
- data.tar.gz: 58046cc6213e103480928fb4bcc908a5cdc3b4848881aeba4d54af956690f98081b66bf8e492127205e643a62a9396283dd7d0a6d1cf364698fe04c947b0d731
6
+ metadata.gz: 699883656bff1c2adc7e08fcbae41006e4be244a256ffebe30b54b891b51dde4367f412ca4616b6a35571b0c2c892ee4f207696fa42575eb276e203295869260
7
+ data.tar.gz: 1edd11e88318b33b950626aae9b7615e0e5bf007ae74bc0e5a68582979f9d6741c5120b9ea4551fd1a3a675890a43d56ca69fa857be3a54b7dd9c9a5b0836677
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
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 Sidekiq library provides a drop in integration for monitoring any Sidekiq Job.
4
4
 
5
5
 
6
- #### NOTE: Version 3.0.0 changes the integration method from 2.x.x. This is a breaking change. You now add the middleware in the Sidekiq initializer. You can opt of out telemetry for specific jobs with a sidekiq_options (see below)
6
+ #### NOTE: Version 3.0.0 changes the integration method from 2.x.x - you now add middleware in the Sidekiq initializer. This significantly reduces the integration overhead, however it is a BREAKING CHANGE. Existing users who would like to migrate to version 3.x.x should [contact support](mailto:support@cronitor.io) for assistance with the migration.
7
7
 
8
8
  ## Installation
9
9
 
@@ -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,22 +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
89
 
98
90
  ## Development
99
91
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq::Cronitor
4
+ class PeriodicJobs
5
+ def self.sync_schedule!
6
+ monitors_payload = []
7
+ loops = Sidekiq::Periodic::LoopSet.new
8
+ loops.each do |lop|
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' }
13
+ end
14
+
15
+ Cronitor::Monitor.put(monitors: monitors_payload)
16
+ rescue Cronitor::Error => e
17
+ Sidekiq.logger.error("[cronitor] error during #{name}.#{__method__}: #{e}")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sidekiq::Cronitor
4
+ class SidekiqScheduler
5
+ def self.sync_schedule!
6
+ monitors_payload = []
7
+ # go through the scheduled jobs and find cron defined ones
8
+ Sidekiq.get_schedule.each do |_k, v|
9
+ # make sure the job has a cron or every definition, we skip non cron/every defined jobs for now
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' }
18
+ end
19
+
20
+ Cronitor::Monitor.put(monitors: monitors_payload)
21
+ rescue Cronitor::Error => e
22
+ Sidekiq.logger.error("[cronitor] error during #{name}.#{__method__}: #{e}")
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Cronitor
3
- VERSION = '3.1.0'
3
+ VERSION = '3.4.0'
4
4
  end
5
5
  end
@@ -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(:cronitor_disabled, nil)
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(:cronitor_key, nil) ||
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(:cronitor, {})
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
@@ -51,7 +59,7 @@ module Sidekiq::Cronitor
51
59
 
52
60
  Sidekiq.logger.debug("[cronitor] ping: worker=#{job_key(worker)} state=#{state} message=#{message}")
53
61
 
54
- cronitor(worker).ping(state: state)
62
+ cronitor(worker).ping(state: state, message: message)
55
63
  rescue Cronitor::Error => e
56
64
  Sidekiq.logger.error("[cronitor] error during ping: worker=#{job_key(worker)} error=#{e.message}")
57
65
  rescue => e
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.0
4
+ version: 3.4.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-04 00:00:00.000000000 Z
12
+ date: 2022-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '4.0'
34
+ version: '5.0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '4.0'
41
+ version: '5.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -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: