mini_scheduler 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/mini_scheduler.rb +20 -14
- data/lib/mini_scheduler/manager.rb +19 -17
- data/lib/mini_scheduler/schedule.rb +6 -1
- data/lib/mini_scheduler/schedule_info.rb +2 -2
- data/lib/mini_scheduler/version.rb +1 -1
- data/lib/mini_scheduler/views/scheduler.erb +10 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61de19d47b5090c36a179869a01800506ee364629db64f47df963426c1d9a8b6
|
4
|
+
data.tar.gz: faa1b86a2d625fa570b26dd8ad8a2ccdb15fcd6029f1d93ad67ddefb0301342a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 931ae1731d9c1b49b3c861ec5b401d317e436f9548494c6fc9cd7b242c5d9bd932459bdf5598f9e7ca24abe8c46d585a43d75cac8a2772f7a04bc77fcf6ad27d
|
7
|
+
data.tar.gz: 82ef45be2249b8c5d6834aeeb13f3f72e4b23604436a68246bba46350ad49255d0f9adf6ac262f685c189d9fc6670c8247776ab3b2d4eaf1f9b7e55b87a63515
|
data/README.md
CHANGED
@@ -49,6 +49,7 @@ end
|
|
49
49
|
|
50
50
|
Options for schedules:
|
51
51
|
|
52
|
+
* **queue** followed by a queue name, like "queue :email", default queue is "default"
|
52
53
|
* **every** followed by a duration in seconds, like "every 1.hour".
|
53
54
|
* **daily at:** followed by a duration since midnight, like "daily at: 12.hours", to run only once per day at a specific time.
|
54
55
|
|
data/lib/mini_scheduler.rb
CHANGED
@@ -52,24 +52,30 @@ module MiniScheduler
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.start
|
55
|
-
|
55
|
+
schedules = Manager.discover_schedules
|
56
56
|
|
57
|
-
Manager.
|
58
|
-
manager.
|
59
|
-
end
|
57
|
+
Manager.discover_queues.each do |queue|
|
58
|
+
manager = Manager.new(queue: queue)
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
if !self.skip_schedule || !self.skip_schedule.call
|
65
|
-
manager.tick
|
66
|
-
end
|
67
|
-
rescue => e
|
68
|
-
# the show must go on
|
69
|
-
handle_job_exception(e, message: "While ticking scheduling manager")
|
60
|
+
schedules.each do |schedule|
|
61
|
+
if schedule.queue == queue
|
62
|
+
manager.ensure_schedule!(schedule)
|
70
63
|
end
|
64
|
+
end
|
71
65
|
|
72
|
-
|
66
|
+
Thread.new do
|
67
|
+
while true
|
68
|
+
begin
|
69
|
+
if !self.skip_schedule || !self.skip_schedule.call
|
70
|
+
manager.tick
|
71
|
+
end
|
72
|
+
rescue => e
|
73
|
+
# the show must go on
|
74
|
+
handle_job_exception(e, message: "While ticking scheduling manager")
|
75
|
+
end
|
76
|
+
|
77
|
+
sleep 1
|
78
|
+
end
|
73
79
|
end
|
74
80
|
end
|
75
81
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module MiniScheduler
|
2
2
|
class Manager
|
3
|
-
attr_accessor :random_ratio, :redis, :enable_stats
|
3
|
+
attr_accessor :random_ratio, :redis, :enable_stats, :queue
|
4
4
|
|
5
5
|
class Runner
|
6
6
|
def initialize(manager)
|
@@ -168,11 +168,13 @@ module MiniScheduler
|
|
168
168
|
end
|
169
169
|
|
170
170
|
def initialize(options = nil)
|
171
|
+
@queue = options && options[:queue] || "default"
|
172
|
+
|
171
173
|
@redis = MiniScheduler.redis
|
172
174
|
@random_ratio = 0.1
|
173
175
|
unless options && options[:skip_runner]
|
174
176
|
@runner = Runner.new(self)
|
175
|
-
self.class.current = self
|
177
|
+
self.class.current[@queue] = self
|
176
178
|
end
|
177
179
|
|
178
180
|
@hostname = options && options[:hostname]
|
@@ -186,11 +188,7 @@ module MiniScheduler
|
|
186
188
|
end
|
187
189
|
|
188
190
|
def self.current
|
189
|
-
@current
|
190
|
-
end
|
191
|
-
|
192
|
-
def self.current=(manager)
|
193
|
-
@current = manager
|
191
|
+
@current ||= {}
|
194
192
|
end
|
195
193
|
|
196
194
|
def hostname
|
@@ -225,7 +223,7 @@ module MiniScheduler
|
|
225
223
|
end
|
226
224
|
|
227
225
|
def reschedule_orphans_on!(hostname = nil)
|
228
|
-
redis.zrange(Manager.queue_key(hostname), 0, -1).each do |key|
|
226
|
+
redis.zrange(Manager.queue_key(queue, hostname), 0, -1).each do |key|
|
229
227
|
klass = get_klass(key)
|
230
228
|
next unless klass
|
231
229
|
info = schedule_info(klass)
|
@@ -253,14 +251,14 @@ module MiniScheduler
|
|
253
251
|
end
|
254
252
|
|
255
253
|
def schedule_next_job(hostname = nil)
|
256
|
-
(key, due), _ = redis.zrange Manager.queue_key(hostname), 0, 0, withscores: true
|
254
|
+
(key, due), _ = redis.zrange Manager.queue_key(queue, hostname), 0, 0, withscores: true
|
257
255
|
return unless key
|
258
256
|
|
259
257
|
if due.to_i <= Time.now.to_i
|
260
258
|
klass = get_klass(key)
|
261
259
|
unless klass
|
262
260
|
# corrupt key, nuke it (renamed job or something)
|
263
|
-
redis.zrem Manager.queue_key(hostname), key
|
261
|
+
redis.zrem Manager.queue_key(queue, hostname), key
|
264
262
|
return
|
265
263
|
end
|
266
264
|
info = schedule_info(klass)
|
@@ -281,7 +279,7 @@ module MiniScheduler
|
|
281
279
|
|
282
280
|
def stop!
|
283
281
|
@runner.stop!
|
284
|
-
self.class.current
|
282
|
+
self.class.current.delete(@queue)
|
285
283
|
end
|
286
284
|
|
287
285
|
def keep_alive_duration
|
@@ -293,11 +291,15 @@ module MiniScheduler
|
|
293
291
|
end
|
294
292
|
|
295
293
|
def lock
|
296
|
-
MiniScheduler::DistributedMutex.synchronize(Manager.lock_key, MiniScheduler.redis) do
|
294
|
+
MiniScheduler::DistributedMutex.synchronize(Manager.lock_key(queue), MiniScheduler.redis) do
|
297
295
|
yield
|
298
296
|
end
|
299
297
|
end
|
300
298
|
|
299
|
+
def self.discover_queues
|
300
|
+
ObjectSpace.each_object(MiniScheduler::Schedule).map(&:queue).to_set
|
301
|
+
end
|
302
|
+
|
301
303
|
def self.discover_schedules
|
302
304
|
# hack for developemnt reloader is crazytown
|
303
305
|
# multiple classes with same name can be in
|
@@ -326,15 +328,15 @@ module MiniScheduler
|
|
326
328
|
@identity_key ||= "_scheduler_#{hostname}:#{Process.pid}:#{self.class.seq}:#{SecureRandom.hex}"
|
327
329
|
end
|
328
330
|
|
329
|
-
def self.lock_key
|
330
|
-
"_scheduler_lock_"
|
331
|
+
def self.lock_key(queue)
|
332
|
+
"_scheduler_lock_#{queue}_"
|
331
333
|
end
|
332
334
|
|
333
|
-
def self.queue_key(hostname = nil)
|
335
|
+
def self.queue_key(queue, hostname = nil)
|
334
336
|
if hostname
|
335
|
-
"_scheduler_queue_#{hostname}_"
|
337
|
+
"_scheduler_queue_#{queue}_#{hostname}_"
|
336
338
|
else
|
337
|
-
"_scheduler_queue_"
|
339
|
+
"_scheduler_queue_#{queue}_"
|
338
340
|
end
|
339
341
|
end
|
340
342
|
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module MiniScheduler::Schedule
|
2
2
|
|
3
|
+
def queue(value = nil)
|
4
|
+
@queue = value.to_s if value
|
5
|
+
@queue ||= "default"
|
6
|
+
end
|
7
|
+
|
3
8
|
def daily(options = nil)
|
4
9
|
if options
|
5
10
|
@daily = options
|
@@ -10,7 +15,7 @@ module MiniScheduler::Schedule
|
|
10
15
|
def every(duration = nil)
|
11
16
|
if duration
|
12
17
|
@every = duration
|
13
|
-
if manager = MiniScheduler::Manager.current
|
18
|
+
if manager = MiniScheduler::Manager.current[queue]
|
14
19
|
manager.ensure_schedule!(self)
|
15
20
|
end
|
16
21
|
end
|
@@ -120,9 +120,9 @@ module MiniScheduler
|
|
120
120
|
|
121
121
|
def queue_key
|
122
122
|
if @klass.is_per_host
|
123
|
-
Manager.queue_key(@manager.hostname)
|
123
|
+
Manager.queue_key(@manager.queue, @manager.hostname)
|
124
124
|
else
|
125
|
-
Manager.queue_key
|
125
|
+
Manager.queue_key(@manager.queue)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -7,16 +7,17 @@
|
|
7
7
|
<div class="container">
|
8
8
|
<div class="row">
|
9
9
|
|
10
|
-
<div class="col-md-
|
10
|
+
<div class="col-md-12">
|
11
11
|
<% if @schedules.length > 0 %>
|
12
12
|
<table class="table table-striped table-bordered table-white" style="width: 100%; margin: 0; table-layout:fixed;">
|
13
13
|
<thead>
|
14
14
|
<th style="width: 30%">Worker</th>
|
15
|
-
<th style="width:
|
16
|
-
<th style="width:
|
17
|
-
<th style="width:
|
18
|
-
<th style="width:
|
19
|
-
<th style="width:
|
15
|
+
<th style="width: 10%">Last Run</th>
|
16
|
+
<th style="width: 10%">Last Result</th>
|
17
|
+
<th style="width: 10%">Last Duration</th>
|
18
|
+
<th style="width: 10%">Last Owner</th>
|
19
|
+
<th style="width: 10%">Next Run Due</th>
|
20
|
+
<th style="width: 10%">Queue</th>
|
20
21
|
<th style="width: 10%">Actions</th>
|
21
22
|
</thead>
|
22
23
|
<% @schedules.each do |schedule| %>
|
@@ -49,6 +50,9 @@
|
|
49
50
|
<%= relative_time(Time.at(next_run)) %>
|
50
51
|
<% end %>
|
51
52
|
</td>
|
53
|
+
<td>
|
54
|
+
<%= schedule.queue %>
|
55
|
+
</td>
|
52
56
|
<td>
|
53
57
|
<form action="<%= "#{root_path}scheduler/#{schedule}/trigger" %>" method="post">
|
54
58
|
<%= csrf_tag if respond_to?(:csrf_tag) %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|