sidekiq-cronitor 1.0.0.alpha → 1.0.0.alpha2

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
  SHA1:
3
- metadata.gz: a9be623c484eb06cd00eb0c7687351252266e2f5
4
- data.tar.gz: 473caa08118deaae2c4ff3985fdfe31fb59ad2f8
3
+ metadata.gz: d7a312993ccafb8425bb94bfff6deec07241ff5e
4
+ data.tar.gz: 96bba8e59b67eafaf8dda5e42a2b5c4804e41344
5
5
  SHA512:
6
- metadata.gz: 66712be66af8fab84b8a41763f806bc411278841a984996e91e23cd841fdb2adcc2f49841ec1dc4417dfc9a9edffa602304fbbfdc04ffa27407c53b51cc8d714
7
- data.tar.gz: c3f8671045720143dc77b8e686bafe12a5af8705969319a5f3181b3c8ab09f500c9883ec935ed13ce812ca19f579efce71bca028277b858308c3aadf8de3840e
6
+ metadata.gz: 65f500c417e836ee253b45c156dcf4fe39ab6e9103d892378e7a0bce8c74f5d1811d0b9359d3a1d953dc8ee32204ae0902a93c2f101c671f690d34e678379253
7
+ data.tar.gz: 59b58af7800b9a659b0b59f57c3972b50cfcd64459c2975c75728aa745b405a69fbf6f5fe92f1b02041752b1eaf6cc3010b0a5ec8b1f7d6880139404c4aa8b89
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -48,18 +48,21 @@ module Sidekiq::Cronitor
48
48
  # Default monitor name to sidekiq worker (class) name
49
49
  kwargs[:opts][:name] ||= name
50
50
 
51
- # If we're using Sidekiq::Cron and there's a job for this class then use
52
- # it's cron schedule for a default not_on_schedudle rule, and tag this as
53
- # a cron job
54
- if defined?(Sidekiq::Cron) && job = Sidekiq::Cron::Job.all.find { |j| j.klass == name }
55
- kwargs[:opts][:rules] ||= [{rule_type: "not_on_schedule", value: job.cron}]
56
- kwargs[:opts][:tags] ||= ["cron-job", "sidekiq-cron", "sidekiq-cronitor"]
57
- end
58
-
59
51
  # Some hints about where this monitor came from
60
- kwargs[:opts][:tags] ||= ["sidekiq-cronitor"]
52
+ kwargs[:opts][:tags] ||= []
53
+ kwargs[:opts][:tags] << "sidekiq-cronitor"
54
+ if environment = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || Sidekiq.options[:environment]
55
+ kwargs[:opts][:tags] << environment
56
+ end
61
57
  kwargs[:opts][:note] ||= "Created by sidekiq-cronitor"
62
58
 
59
+ # If we can find a schedule for this worker then we can automatically add
60
+ # a not_on_schedule rule and tag it as a cron-job
61
+ if schedule = cronitor_schedule
62
+ kwargs[:opts][:rules] ||= [{rule_type: "not_on_schedule", value: schedule}]
63
+ kwargs[:opts][:tags] << "cron-job"
64
+ end
65
+
63
66
  begin
64
67
  @cronitor = Cronitor.new(**kwargs)
65
68
  rescue Cronitor::Error => e
@@ -68,6 +71,31 @@ module Sidekiq::Cronitor
68
71
  @cronitor = nil
69
72
  end
70
73
  end
74
+
75
+ private def cronitor_schedule
76
+ name = self.name
77
+
78
+ if defined?(Sidekiq::Cron)
79
+ # If we can find a Sidekiq::Cron job with a matching worker class
80
+ # then presume its schedule.
81
+ Sidekiq::Cron::Job.all.each do |job|
82
+ if job.klass == name
83
+ return job.cron
84
+ end
85
+ end
86
+ elsif defined?(Sidekiq::Periodic)
87
+ # If we can find a Sidekiq Enterprise Periodic Loop with a matching
88
+ # worker class then presume its schedule.
89
+ Sidekiq::Periodic::LoopSet.new.each do |loop_|
90
+ if loop_.klass == name
91
+ return loop_.schedule
92
+ end
93
+ end
94
+ end
95
+
96
+ # ¯\_(ツ)_/¯
97
+ return nil
98
+ end
71
99
  end
72
100
 
73
101
  class Middleware
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Cronitor
3
- VERSION = "1.0.0.alpha"
3
+ VERSION = "1.0.0.alpha2"
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: 1.0.0.alpha
4
+ version: 1.0.0.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Cochran
@@ -28,7 +28,7 @@ cert_chain:
28
28
  P4lSfmXxsd1C71ckIp0cyXkPhyTtpyS/5hq9HhuUNzEHkSDe36/Rd1xYKV5JxMC2
29
29
  YAttWFUs06lor2q1wwncPaMtUtbWwW35+1IV6xhs2rFY6DD/I6ZkK3GnHdY=
30
30
  -----END CERTIFICATE-----
31
- date: 2017-12-01 00:00:00.000000000 Z
31
+ date: 2017-12-10 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sidekiq
metadata.gz.sig CHANGED
Binary file