sidekiq-scheduler 2.0.18 → 2.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/sidekiq-scheduler/job_presenter.rb +4 -0
- data/lib/sidekiq-scheduler/schedule.rb +4 -4
- data/lib/sidekiq-scheduler/version.rb +1 -1
- data/lib/sidekiq-scheduler/web.rb +5 -0
- data/lib/sidekiq/scheduler.rb +40 -2
- data/web/locales/cs.yml +2 -0
- data/web/locales/en.yml +2 -0
- data/web/locales/es.yml +2 -0
- data/web/locales/zh-cn.yml +2 -0
- data/web/views/recurring_jobs.erb +6 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd4d7812270a42a1fba60eb58d6bb15e64cea545
|
4
|
+
data.tar.gz: f19980d703c2914483df61357fc3edd7d5fb4887
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 628c7aa26722c33a2744b3239412a307a59d9de62ac5182144eec62098942b5c31b902d24c22089b5bc6c8f5da8141ede0fbc29c42cc72f3f00301d329f929ea
|
7
|
+
data.tar.gz: dc1e2a7c303f10fee40dadb5fa7cdb3ad6b8c6e4c437c478ec1beb65c1f32bf2cb88955b7c7e1c625a5d4a628915d84b71795fe4318585904e4e5ca62fdbabea
|
data/README.md
CHANGED
@@ -145,6 +145,22 @@ seconds past the minute).
|
|
145
145
|
A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
|
146
146
|
for handling the heavy lifting of the actual scheduling engine.
|
147
147
|
|
148
|
+
### Enabling/Disabling jobs
|
149
|
+
|
150
|
+
By default all the jobs are enabled. There is an option at job's configuration to change
|
151
|
+
this behavior.
|
152
|
+
|
153
|
+
``` yaml
|
154
|
+
clear_leaderboards_moderator:
|
155
|
+
every: "30s"
|
156
|
+
class: CheckDaemon
|
157
|
+
enabled: false
|
158
|
+
description: "This job is disabled by default"
|
159
|
+
```
|
160
|
+
|
161
|
+
However, the flag can be changed through the web interface at the Recurring Jobs tab.
|
162
|
+
|
163
|
+
NOTE: Changes made thorugh the UI supersede job's configuration, even after a restart.
|
148
164
|
|
149
165
|
### Loading the schedule
|
150
166
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'hashie'
|
2
|
-
require '
|
2
|
+
require 'json'
|
3
3
|
|
4
4
|
module SidekiqScheduler
|
5
5
|
module Schedule
|
@@ -71,7 +71,7 @@ module SidekiqScheduler
|
|
71
71
|
get_all_schedules
|
72
72
|
else
|
73
73
|
encoded_schedule = Sidekiq.redis { |r| r.hget(:schedules, name) }
|
74
|
-
encoded_schedule.nil? ? nil :
|
74
|
+
encoded_schedule.nil? ? nil : JSON(encoded_schedule)
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -83,7 +83,7 @@ module SidekiqScheduler
|
|
83
83
|
|
84
84
|
Sidekiq.redis { |r| r.hgetall(:schedules) }.tap do |h|
|
85
85
|
h.each do |name, config|
|
86
|
-
schedules[name] =
|
86
|
+
schedules[name] = JSON(config)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -103,7 +103,7 @@ module SidekiqScheduler
|
|
103
103
|
def set_schedule(name, config)
|
104
104
|
existing_config = get_schedule(name)
|
105
105
|
unless existing_config && existing_config == config
|
106
|
-
Sidekiq.redis { |r| r.hset(:schedules, name,
|
106
|
+
Sidekiq.redis { |r| r.hset(:schedules, name, JSON(config)) }
|
107
107
|
Sidekiq.redis { |r| r.sadd(:schedules_changed, name) }
|
108
108
|
end
|
109
109
|
config
|
@@ -18,6 +18,11 @@ module SidekiqScheduler
|
|
18
18
|
Sidekiq::Scheduler.enqueue_job(schedule)
|
19
19
|
redirect "#{root_path}recurring-jobs"
|
20
20
|
end
|
21
|
+
|
22
|
+
app.get '/recurring-jobs/:name/toggle' do
|
23
|
+
Sidekiq::Scheduler.toggle_job_enabled(params[:name])
|
24
|
+
redirect "#{root_path}recurring-jobs"
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
data/lib/sidekiq/scheduler.rb
CHANGED
@@ -2,13 +2,14 @@ require 'rufus/scheduler'
|
|
2
2
|
require 'thwait'
|
3
3
|
require 'sidekiq/util'
|
4
4
|
require 'sidekiq-scheduler/manager'
|
5
|
+
require 'json'
|
5
6
|
|
6
7
|
module Sidekiq
|
7
8
|
class Scheduler
|
8
9
|
extend Sidekiq::Util
|
9
10
|
|
10
11
|
REGISTERED_JOBS_THRESHOLD_IN_SECONDS = 24 * 60 * 60
|
11
|
-
RUFUS_METADATA_KEYS = %w(description at cron every in interval)
|
12
|
+
RUFUS_METADATA_KEYS = %w(description at cron every in interval enabled)
|
12
13
|
|
13
14
|
# We expect rufus jobs to have #params
|
14
15
|
Rufus::Scheduler::Job.module_eval do
|
@@ -335,10 +336,29 @@ module Sidekiq
|
|
335
336
|
|
336
337
|
# Returns the key of the Redis hash for job's execution times hash
|
337
338
|
#
|
339
|
+
# @return [String] with the key
|
338
340
|
def next_times_key
|
339
341
|
'sidekiq-scheduler:next_times'
|
340
342
|
end
|
341
343
|
|
344
|
+
# Returns the Redis's key for saving schedule states.
|
345
|
+
#
|
346
|
+
# @return [String] with the key
|
347
|
+
def schedules_state_key
|
348
|
+
'sidekiq-scheduler:states'
|
349
|
+
end
|
350
|
+
|
351
|
+
def job_enabled?(name)
|
352
|
+
job = Sidekiq.schedule[name]
|
353
|
+
schedule_state(name).fetch('enabled', job.fetch('enabled', true)) if job
|
354
|
+
end
|
355
|
+
|
356
|
+
def toggle_job_enabled(name)
|
357
|
+
state = schedule_state(name)
|
358
|
+
state['enabled'] = !job_enabled?(name)
|
359
|
+
set_schedule_state(name, state)
|
360
|
+
end
|
361
|
+
|
342
362
|
private
|
343
363
|
|
344
364
|
def new_rufus_scheduler
|
@@ -353,7 +373,7 @@ module Sidekiq
|
|
353
373
|
opts = { :job => true, :tags => [name] }
|
354
374
|
|
355
375
|
rufus_scheduler.send(interval_type, *args, opts) do |job, time|
|
356
|
-
idempotent_job_enqueue(name, time, sanitize_job_config(config))
|
376
|
+
idempotent_job_enqueue(name, time, sanitize_job_config(config)) if job_enabled?(name)
|
357
377
|
end
|
358
378
|
end
|
359
379
|
|
@@ -361,6 +381,24 @@ module Sidekiq
|
|
361
381
|
config.reject { |k, _| RUFUS_METADATA_KEYS.include?(k) }
|
362
382
|
end
|
363
383
|
|
384
|
+
# Retrieves a schedule state
|
385
|
+
#
|
386
|
+
# @param name [String] with the schedule's name
|
387
|
+
# @return [Hash] with the schedule's state
|
388
|
+
def schedule_state(name)
|
389
|
+
state = Sidekiq.redis { |r| r.hget(schedules_state_key, name) }
|
390
|
+
|
391
|
+
state ? JSON(state) : {}
|
392
|
+
end
|
393
|
+
|
394
|
+
# Saves a schedule state
|
395
|
+
#
|
396
|
+
# @param name [String] with the schedule's name
|
397
|
+
# @param name [Hash] with the schedule's state
|
398
|
+
def set_schedule_state(name, state)
|
399
|
+
Sidekiq.redis { |r| r.hset(schedules_state_key, name, JSON(state)) }
|
400
|
+
end
|
401
|
+
|
364
402
|
end
|
365
403
|
end
|
366
404
|
end
|
data/web/locales/cs.yml
CHANGED
data/web/locales/en.yml
CHANGED
data/web/locales/es.yml
CHANGED
data/web/locales/zh-cn.yml
CHANGED
@@ -26,11 +26,16 @@
|
|
26
26
|
<a href="<%= root_path %>queues/<%= job.queue %>"><%= job.queue %></a>
|
27
27
|
</td>
|
28
28
|
<td><%= job['args'] %></td>
|
29
|
-
<td
|
29
|
+
<td><span style="<%= 'text-decoration:line-through' unless job.enabled? %>">
|
30
|
+
<%= job.next_time || t('no_next_time') %>
|
31
|
+
</span></td>
|
30
32
|
<td class="text-center">
|
31
33
|
<a class="btn btn-warn btn-xs" href="<%= root_path %>recurring-jobs/<%= URI.escape(job.name) %>/enqueue">
|
32
34
|
<%= t('enqueue_now') %>
|
33
35
|
</a>
|
36
|
+
<a class="btn <%= job.enabled? ? "btn-primary" : "btn-warn"%> btn-xs" href="<%= root_path %>recurring-jobs/<%= URI.escape(job.name) %>/toggle">
|
37
|
+
<%= job.enabled? ? t('disable') : t('enable') %>
|
38
|
+
</a>
|
34
39
|
</td>
|
35
40
|
</tr>
|
36
41
|
<% end %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morton Jonuschat
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-10-
|
12
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -67,20 +67,6 @@ dependencies:
|
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 3.1.8
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: multi_json
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ~>
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '1'
|
77
|
-
type: :runtime
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ~>
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '1'
|
84
70
|
- !ruby/object:Gem::Dependency
|
85
71
|
name: tilt
|
86
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,6 +165,20 @@ dependencies:
|
|
179
165
|
- - ~>
|
180
166
|
- !ruby/object:Gem::Version
|
181
167
|
version: '0'
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: byebug
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
182
|
- !ruby/object:Gem::Dependency
|
183
183
|
name: activejob
|
184
184
|
requirement: !ruby/object:Gem::Requirement
|