sidekiq-cronitor 3.7.0 → 3.8.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/lib/sidekiq/cronitor/periodic_jobs.rb +11 -3
- data/lib/sidekiq/cronitor/sidekiq_scheduler.rb +1 -1
- data/lib/sidekiq/cronitor/version.rb +1 -1
- data/lib/sidekiq/cronitor.rb +27 -36
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73f1021e94b3744466768b9f4f6d3d1378c979207be5ff5001fd3ba569633d34
|
4
|
+
data.tar.gz: 9fad65ced9e8198bef92ecdfdb3cf35021f92b991f8d261ce8a519556aed5611
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da13ce558bda83799ad8a5d8644bf74f961fdea6f36ee7b17bbaf7450d2c20c7f92262689a2868f2f4ae1a7a02c638c645e0b08c77d98f12e27ba26fe99936d9
|
7
|
+
data.tar.gz: a2b79972087d00cdfe6858399b12e8165918424764130d79170b03befb86fb8d9608fd80fcd093451a6fe3996527686c47e7697d672b99ffe3073a0452638d05
|
@@ -6,7 +6,7 @@ module Sidekiq::Cronitor
|
|
6
6
|
monitors_payload = []
|
7
7
|
loops = Sidekiq::Periodic::LoopSet.new
|
8
8
|
loops.each do |lop|
|
9
|
-
if
|
9
|
+
if parsed_options(lop).has_key?('cronitor_enabled') || Object.const_get(lop.klass).sidekiq_options.has_key?('cronitor_enabled')
|
10
10
|
next unless fetch_option(lop, 'cronitor_enabled', Cronitor.auto_discover_sidekiq)
|
11
11
|
else
|
12
12
|
next if fetch_option(lop, 'cronitor_disabled', !Cronitor.auto_discover_sidekiq)
|
@@ -29,9 +29,17 @@ module Sidekiq::Cronitor
|
|
29
29
|
Sidekiq.logger.error("[cronitor] error during #{name}.#{__method__}: #{e}")
|
30
30
|
end
|
31
31
|
|
32
|
+
def self.parsed_options(lop)
|
33
|
+
if lop.options.is_a?(String)
|
34
|
+
JSON.parse(lop.options)
|
35
|
+
else
|
36
|
+
lop.options
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
32
40
|
def self.fetch_option(lop, key, default = nil)
|
33
|
-
lop.
|
34
|
-
lop.klass.
|
41
|
+
parsed_options(lop).fetch(key, default) ||
|
42
|
+
Object.const_get(lop.klass).sidekiq_options.fetch(key, default)
|
35
43
|
end
|
36
44
|
end
|
37
45
|
end
|
@@ -13,7 +13,7 @@ module Sidekiq::Cronitor
|
|
13
13
|
job_klass = Object.const_get(v['class'])
|
14
14
|
job_key = job_klass.sidekiq_options.fetch('cronitor_key', v['class'])
|
15
15
|
|
16
|
-
if job_klass.sidekiq_options
|
16
|
+
if job_klass.sidekiq_options.has_key?('cronitor_enabled')
|
17
17
|
next unless job_klass.sidekiq_options.fetch('cronitor_enabled', Cronitor.auto_discover_sidekiq)
|
18
18
|
else
|
19
19
|
next if job_klass.sidekiq_options.fetch('cronitor_disabled', !Cronitor.auto_discover_sidekiq)
|
data/lib/sidekiq/cronitor.rb
CHANGED
@@ -13,72 +13,63 @@ end
|
|
13
13
|
|
14
14
|
module Sidekiq::Cronitor
|
15
15
|
class ServerMiddleware
|
16
|
-
|
17
|
-
|
16
|
+
# @param [Object] worker the instance of the job that was queued
|
17
|
+
# @param [Hash] job_payload the full job payload
|
18
|
+
# * @see https://github.com/sidekiq/sidekiq/wiki/Job-Format
|
19
|
+
# @param [String] queue the name of the queue the job was pulled from
|
20
|
+
# @yield the next middleware in the chain or worker `perform` method
|
21
|
+
def call(worker, job_payload, queue)
|
22
|
+
ping(job_payload: job_payload, state: 'run')
|
18
23
|
|
19
24
|
result = yield
|
20
25
|
rescue => e
|
21
|
-
ping(
|
26
|
+
ping(job_payload: job_payload, state: 'fail', message: e.to_s)
|
22
27
|
|
23
28
|
raise e
|
24
29
|
else
|
25
|
-
ping(
|
30
|
+
ping(job_payload: job_payload, state: 'complete')
|
26
31
|
result # to be consistent with client middleware, return results of yield
|
27
32
|
end
|
28
33
|
|
29
34
|
private
|
30
35
|
|
31
|
-
def cronitor(
|
32
|
-
Cronitor::Monitor.new(job_key(
|
36
|
+
def cronitor(job_payload)
|
37
|
+
Cronitor::Monitor.new(job_key(job_payload))
|
33
38
|
end
|
34
39
|
|
35
|
-
def cronitor_disabled?(
|
36
|
-
if
|
37
|
-
!
|
40
|
+
def cronitor_disabled?(job_payload)
|
41
|
+
if job_payload.has_key?("cronitor_enabled")
|
42
|
+
!job_payload.fetch("cronitor_enabled", Cronitor.auto_discover_sidekiq)
|
38
43
|
else
|
39
|
-
|
44
|
+
job_payload.fetch("cronitor_disabled", options(job_payload).fetch("disabled", !Cronitor.auto_discover_sidekiq))
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
43
|
-
def job_key(
|
44
|
-
|
45
|
-
options(worker).fetch(:key, worker.class.name)
|
48
|
+
def job_key(job_payload)
|
49
|
+
job_payload['cronitor_key'] || options(job_payload)['key'] || job_payload['class']
|
46
50
|
end
|
47
51
|
|
48
|
-
def
|
49
|
-
return unless defined?(Sidekiq::Periodic)
|
50
|
-
|
51
|
-
periodic_job = Sidekiq::Periodic::LoopSet.new.find do |lop|
|
52
|
-
lop.history.find { |j| j[0] == worker.jid }
|
53
|
-
end
|
54
|
-
|
55
|
-
periodic_job.present? && periodic_job.options.fetch('cronitor_key', nil)
|
56
|
-
end
|
57
|
-
|
58
|
-
def options(worker)
|
52
|
+
def options(job_payload)
|
59
53
|
# eventually we will delete this method of passing options
|
60
54
|
# ultimately we want all cronitor options to be top level keys
|
61
|
-
|
62
|
-
# symbolize_keys is a rails helper, so only use it if it's defined
|
63
|
-
opts = opts.symbolize_keys if opts.respond_to?(:symbolize_keys)
|
64
|
-
opts
|
55
|
+
job_payload.fetch("cronitor", {})
|
65
56
|
end
|
66
57
|
|
67
|
-
def ping(
|
68
|
-
return unless should_ping?(
|
58
|
+
def ping(job_payload:, state:, message: nil)
|
59
|
+
return unless should_ping?(job_payload)
|
69
60
|
|
70
|
-
Sidekiq.logger.debug("[cronitor] ping: worker=#{job_key(
|
61
|
+
Sidekiq.logger.debug("[cronitor] ping: worker=#{job_key(job_payload)} state=#{state} message=#{message}")
|
71
62
|
|
72
|
-
cronitor(
|
63
|
+
cronitor(job_payload).ping(state: state, message: message)
|
73
64
|
rescue Cronitor::Error => e
|
74
|
-
Sidekiq.logger.error("[cronitor] error during ping: worker=#{job_key(
|
65
|
+
Sidekiq.logger.error("[cronitor] error during ping: worker=#{job_key(job_payload)} error=#{e.message}")
|
75
66
|
rescue => e
|
76
|
-
Sidekiq.logger.error("[cronitor] unexpected error: worker=#{job_key(
|
67
|
+
Sidekiq.logger.error("[cronitor] unexpected error: worker=#{job_key(job_payload)} error=#{e.message}")
|
77
68
|
Sidekiq.logger.error(e.backtrace.first)
|
78
69
|
end
|
79
70
|
|
80
|
-
def should_ping?(
|
81
|
-
!cronitor(
|
71
|
+
def should_ping?(job_payload)
|
72
|
+
!cronitor(job_payload).api_key.nil? && !cronitor_disabled?(job_payload)
|
82
73
|
end
|
83
74
|
end
|
84
75
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-cronitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeke Gabrielse
|
8
8
|
- Samuel Cochran
|
9
9
|
- Kevin Tom
|
10
10
|
- August Flanagan
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2025-02-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: sidekiq
|
@@ -118,7 +118,7 @@ homepage: https://github.com/cronitor/sidekiq-cronitor
|
|
118
118
|
licenses:
|
119
119
|
- MIT
|
120
120
|
metadata: {}
|
121
|
-
post_install_message:
|
121
|
+
post_install_message:
|
122
122
|
rdoc_options: []
|
123
123
|
require_paths:
|
124
124
|
- lib
|
@@ -133,8 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
|
-
rubygems_version: 3.1
|
137
|
-
signing_key:
|
136
|
+
rubygems_version: 3.0.3.1
|
137
|
+
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: Monitor your Sidekiq jobs with Cronitor
|
140
140
|
test_files: []
|