sidekiq-heartbeat_monitor 1.0.2.0 → 1.0.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 +8 -0
- data/lib/sidekiq/heartbeat_monitor.rb +4 -0
- data/lib/sidekiq/heartbeat_monitor/config.rb +45 -14
- data/lib/sidekiq/heartbeat_monitor/railtie.rb +15 -0
- data/lib/sidekiq/heartbeat_monitor/tasks/install.rake +9 -0
- data/lib/sidekiq/heartbeat_monitor/test_worker.rb +21 -0
- data/lib/sidekiq/heartbeat_monitor/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63e40fd229b698071996b154e4e03e663be310f9
|
4
|
+
data.tar.gz: 1f6f80eb7e1a17096aa0fab8643f9a8d6dcbb7ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11a89bf560477d9f172c875233ddbe57624e5a2e12ac9c2fa7ac99e9ee2d8225421e75c18adcb5d91c9924407d2524b00f5abeba4744eac407cf8f218fefb06b
|
7
|
+
data.tar.gz: 1ab1b00e3d63905f01319a01128bbe36fc0396b496fe5ff16eee07e311a0bce43b171f71d570366cf8a2c93e64b5ad3ab2b84696195b5a95d0860e1c8eca3e5c
|
data/README.md
CHANGED
@@ -21,6 +21,14 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
**Configuration is required - see the Configuration section below**
|
23
23
|
|
24
|
+
### (Optional) Install Cron Task
|
25
|
+
The gem will automatically try to install your cron task when you run your sidekiq server, however if for some reason it does not install the cron task
|
26
|
+
then you can install it manually using the available rake task command:
|
27
|
+
```
|
28
|
+
rake sidekiq::heartbeat_monitor:install
|
29
|
+
```
|
30
|
+
|
31
|
+
|
24
32
|
### Requirements
|
25
33
|
1. [Dont Repeat For Gem](https://www.github.com/jayelkaake/dont_repeat_for) - To allow you to only send notifications every so often.
|
26
34
|
2. Redis
|
@@ -4,6 +4,10 @@ require 'sidekiq/heartbeat_monitor/config'
|
|
4
4
|
require 'sidekiq/heartbeat_monitor/util'
|
5
5
|
require 'sidekiq/heartbeat_monitor/scheduler'
|
6
6
|
require 'sidekiq/heartbeat_monitor/worker'
|
7
|
+
require 'sidekiq/heartbeat_monitor/test_worker'
|
8
|
+
|
9
|
+
require 'sidekiq/heartbeat_monitor/railtie' if defined?(Rails)
|
10
|
+
|
7
11
|
|
8
12
|
module Sidekiq
|
9
13
|
module HeartbeatMonitor
|
@@ -62,6 +62,44 @@ module Sidekiq
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
+
def self.install_cron_job!(output: false)
|
66
|
+
job = Sidekiq::Cron::Job.find("sidekiq_monitor")
|
67
|
+
|
68
|
+
target_job = Sidekiq::Cron::Job.new(
|
69
|
+
name: 'sidekiq_monitor',
|
70
|
+
cron: '* * * * *',
|
71
|
+
klass: Sidekiq::HeartbeatMonitor::Scheduler
|
72
|
+
)
|
73
|
+
|
74
|
+
if job.present?
|
75
|
+
if job.cron != target_job.cron && job.klass.to_s != target_job.klass
|
76
|
+
unless job.destroy
|
77
|
+
puts "ERROR: An existing cron job was found with the same name but incorrect configuration. An attempt to delete it (to create a new, correctly configured one) failed." if output
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
|
81
|
+
if target_job.save
|
82
|
+
puts "SUCCESS: An existing crob job was found that had the same name but had outdated configuration, so it was deleted and a new one was installed successfully." if output
|
83
|
+
true
|
84
|
+
else
|
85
|
+
puts "ERROR: Sidekiq heartbeat monitor found an existing cron job with the same name but it is configured incorrectly. It was deleted, but a new one could not be created. Run this command again to try adding it manually again and please ensure you can programmatically add sidekiq cron jobs as well." if output
|
86
|
+
false
|
87
|
+
end
|
88
|
+
else
|
89
|
+
puts "SUCCESS: Sidekiq heartbeat monitor cron job already exists and appears to be configured properly so nothing was changed." if output
|
90
|
+
true
|
91
|
+
end
|
92
|
+
else
|
93
|
+
if target_job.save
|
94
|
+
puts "SUCCESS: New cron task was installed successfully." if output
|
95
|
+
true
|
96
|
+
else
|
97
|
+
puts "ERROR: New cron task could not be saved for some reason. Please ensure you can programmatically add sidekiq cron jobs and try again." if output
|
98
|
+
false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
65
103
|
private
|
66
104
|
|
67
105
|
def setup_slack_notifier!(slack_notifier_url)
|
@@ -74,22 +112,15 @@ module Sidekiq
|
|
74
112
|
end
|
75
113
|
|
76
114
|
def install_cron_job!
|
77
|
-
job
|
115
|
+
# Only install the cron job if we're running as a sidekiq server
|
116
|
+
return unless Sidekiq.server?
|
78
117
|
|
79
|
-
|
80
|
-
name: 'sidekiq_monitor',
|
81
|
-
cron: '* * * * *',
|
82
|
-
klass: Sidekiq::HeartbeatMonitor::Scheduler
|
83
|
-
)
|
118
|
+
self.class.install_cron_job!
|
84
119
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
else
|
91
|
-
target_job.save
|
92
|
-
end
|
120
|
+
rescue Redis::CannotConnectError
|
121
|
+
# If we failed to connect at this point then likely Redis is not yet configured at this point in initialization,
|
122
|
+
# so we should just abort
|
123
|
+
false
|
93
124
|
end
|
94
125
|
|
95
126
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'sidekiq/heartbeat_monitor'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Sidekiq
|
5
|
+
module HeartbeatMonitor
|
6
|
+
class Railtie < ::Rails::Railtie
|
7
|
+
railtie_name :sidekiq_heartbeat_monitor
|
8
|
+
|
9
|
+
rake_tasks do
|
10
|
+
path = File.expand_path(__dir__)
|
11
|
+
Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module HeartbeatMonitor
|
3
|
+
##
|
4
|
+
# Used for testing purposes to ensure that the system is working properly.
|
5
|
+
class TestWorker
|
6
|
+
|
7
|
+
include Sidekiq::Worker
|
8
|
+
|
9
|
+
sidekiq_options retry: 0
|
10
|
+
|
11
|
+
def perform(wait_time = 1.second)
|
12
|
+
puts "Internal test worker started and will continue for the next #{wait_time} seconds." if wait_time > 3.seconds
|
13
|
+
|
14
|
+
sleep(wait_time)
|
15
|
+
|
16
|
+
puts "Internal test worker finished after #{wait_time} seconds." if wait_time > 3.seconds
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-heartbeat_monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay El-Kaake
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -183,7 +183,10 @@ files:
|
|
183
183
|
- bin/setup
|
184
184
|
- lib/sidekiq/heartbeat_monitor.rb
|
185
185
|
- lib/sidekiq/heartbeat_monitor/config.rb
|
186
|
+
- lib/sidekiq/heartbeat_monitor/railtie.rb
|
186
187
|
- lib/sidekiq/heartbeat_monitor/scheduler.rb
|
188
|
+
- lib/sidekiq/heartbeat_monitor/tasks/install.rake
|
189
|
+
- lib/sidekiq/heartbeat_monitor/test_worker.rb
|
187
190
|
- lib/sidekiq/heartbeat_monitor/util.rb
|
188
191
|
- lib/sidekiq/heartbeat_monitor/version.rb
|
189
192
|
- lib/sidekiq/heartbeat_monitor/worker.rb
|