sidekiq-cron 1.2.0 → 1.7.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 +5 -5
- data/CHANGELOG.md +122 -0
- data/Gemfile +1 -30
- data/README.md +151 -121
- data/Rakefile +3 -42
- data/lib/sidekiq/cron/job.rb +139 -104
- data/lib/sidekiq/cron/launcher.rb +7 -9
- data/lib/sidekiq/cron/locales/en.yml +2 -0
- data/lib/sidekiq/cron/locales/pt.yml +22 -0
- data/lib/sidekiq/cron/poller.rb +18 -9
- data/lib/sidekiq/cron/schedule_loader.rb +22 -0
- data/lib/sidekiq/cron/support.rb +0 -1
- data/lib/sidekiq/cron/version.rb +7 -0
- data/lib/sidekiq/cron/views/cron.erb +19 -13
- data/lib/sidekiq/cron/views/cron_show.erb +8 -8
- data/lib/sidekiq/cron/web.rb +1 -7
- data/lib/sidekiq/cron/web_extension.rb +8 -21
- data/lib/sidekiq/cron.rb +1 -0
- data/lib/sidekiq/options.rb +18 -0
- data/sidekiq-cron.gemspec +25 -115
- data/test/integration/performance_test.rb +4 -5
- data/test/test_helper.rb +11 -23
- data/test/unit/fixtures/schedule_array.yml +13 -0
- data/test/unit/fixtures/schedule_hash.yml +12 -0
- data/test/unit/fixtures/schedule_string.yml +1 -0
- data/test/unit/job_test.rb +227 -23
- data/test/unit/poller_test.rb +7 -9
- data/test/unit/schedule_loader_test.rb +45 -0
- data/test/unit/web_extension_test.rb +40 -40
- metadata +56 -197
- data/.document +0 -5
- data/.travis.yml +0 -18
- data/Changes.md +0 -82
- data/Dockerfile +0 -32
- data/VERSION +0 -1
- data/config.ru +0 -14
- data/docker-compose.yml +0 -23
- data/examples/web-cron-ui.png +0 -0
- data/lib/sidekiq/cron/views/cron.slim +0 -71
- data/lib/sidekiq/cron/views/cron_show.slim +0 -61
data/lib/sidekiq/cron/job.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'fugit'
|
2
2
|
require 'sidekiq'
|
3
|
-
require 'sidekiq/util'
|
4
3
|
require 'sidekiq/cron/support'
|
4
|
+
require 'sidekiq/options'
|
5
5
|
|
6
6
|
module Sidekiq
|
7
7
|
module Cron
|
8
|
-
|
9
8
|
class Job
|
10
|
-
|
11
|
-
extend Util
|
12
|
-
|
13
|
-
#how long we would like to store informations about previous enqueues
|
9
|
+
# How long we would like to store informations about previous enqueues.
|
14
10
|
REMEMBER_THRESHOLD = 24 * 60 * 60
|
11
|
+
|
12
|
+
# Time format for enqueued jobs.
|
15
13
|
LAST_ENQUEUE_TIME_FORMAT = '%Y-%m-%d %H:%M:%S %z'
|
16
14
|
|
17
|
-
#
|
15
|
+
# Use the exists? method if we're on a newer version of Redis.
|
16
|
+
REDIS_EXISTS_METHOD = Gem.loaded_specs['redis'].version < Gem::Version.new('4.2') ? :exists : :exists?
|
17
|
+
|
18
|
+
# Crucial part of whole enqueuing job.
|
18
19
|
def should_enque? time
|
19
20
|
enqueue = false
|
20
21
|
enqueue = Sidekiq.redis do |conn|
|
@@ -26,18 +27,16 @@ module Sidekiq
|
|
26
27
|
enqueue
|
27
28
|
end
|
28
29
|
|
29
|
-
#
|
30
|
-
# this will clear
|
31
|
-
# not overflow with memory
|
30
|
+
# Remove previous information about run times,
|
31
|
+
# this will clear Redis and make sure that Redis will not overflow with memory.
|
32
32
|
def remove_previous_enques time
|
33
33
|
Sidekiq.redis do |conn|
|
34
34
|
conn.zremrangebyscore(job_enqueued_key, 0, "(#{(time.to_f - REMEMBER_THRESHOLD).to_s}")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
#
|
38
|
+
# Test if job should be enqueued.
|
39
39
|
def test_and_enque_for_time! time
|
40
|
-
#should this job be enqued?
|
41
40
|
if should_enque?(time)
|
42
41
|
enque!
|
43
42
|
|
@@ -45,7 +44,7 @@ module Sidekiq
|
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
|
-
#
|
47
|
+
# Enqueue cron job to queue.
|
49
48
|
def enque! time = Time.now.utc
|
50
49
|
@last_enqueue_time = time.strftime(LAST_ENQUEUE_TIME_FORMAT)
|
51
50
|
|
@@ -73,7 +72,7 @@ module Sidekiq
|
|
73
72
|
|
74
73
|
save_last_enqueue_time
|
75
74
|
add_jid_history jid
|
76
|
-
logger.debug { "enqueued #{@name}: #{@message}" }
|
75
|
+
Sidekiq.logger.debug { "enqueued #{@name}: #{@message}" }
|
77
76
|
end
|
78
77
|
|
79
78
|
def is_active_job?
|
@@ -82,17 +81,27 @@ module Sidekiq
|
|
82
81
|
false
|
83
82
|
end
|
84
83
|
|
84
|
+
def date_as_argument?
|
85
|
+
!!@date_as_argument
|
86
|
+
end
|
87
|
+
|
88
|
+
def enqueue_args
|
89
|
+
date_as_argument? ? @args + [Time.now.to_f] : @args
|
90
|
+
end
|
91
|
+
|
85
92
|
def enqueue_active_job(klass_const)
|
86
|
-
klass_const.set(queue: @queue).perform_later(
|
93
|
+
klass_const.set(queue: @queue).perform_later(*enqueue_args)
|
87
94
|
end
|
88
95
|
|
89
96
|
def enqueue_sidekiq_worker(klass_const)
|
90
|
-
klass_const.set(queue: queue_name_with_prefix).perform_async(
|
97
|
+
klass_const.set(queue: queue_name_with_prefix).perform_async(*enqueue_args)
|
91
98
|
end
|
92
99
|
|
93
|
-
#
|
100
|
+
# Sidekiq worker message.
|
94
101
|
def sidekiq_worker_message
|
95
|
-
@message.is_a?(String) ? Sidekiq.load_json(@message) : @message
|
102
|
+
message = @message.is_a?(String) ? Sidekiq.load_json(@message) : @message
|
103
|
+
message["args"] = enqueue_args
|
104
|
+
message
|
96
105
|
end
|
97
106
|
|
98
107
|
def queue_name_with_prefix
|
@@ -117,8 +126,8 @@ module Sidekiq
|
|
117
126
|
queue_name
|
118
127
|
end
|
119
128
|
|
120
|
-
#
|
121
|
-
# queue, it
|
129
|
+
# Active Job has different structure how it is loading data from Sidekiq
|
130
|
+
# queue, it creates a wrapper around job.
|
122
131
|
def active_job_message
|
123
132
|
{
|
124
133
|
'class' => 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper',
|
@@ -129,13 +138,13 @@ module Sidekiq
|
|
129
138
|
'job_class' => @klass,
|
130
139
|
'job_id' => SecureRandom.uuid,
|
131
140
|
'queue_name' => @queue_name_with_prefix,
|
132
|
-
'arguments' =>
|
141
|
+
'arguments' => enqueue_args
|
133
142
|
}]
|
134
143
|
}
|
135
144
|
end
|
136
145
|
|
137
|
-
#
|
138
|
-
#
|
146
|
+
# Load cron jobs from Hash.
|
147
|
+
# Input structure should look like:
|
139
148
|
# {
|
140
149
|
# 'name_of_job' => {
|
141
150
|
# 'class' => 'MyClass',
|
@@ -157,15 +166,15 @@ module Sidekiq
|
|
157
166
|
load_from_array array
|
158
167
|
end
|
159
168
|
|
160
|
-
#
|
161
|
-
# If exists old jobs in
|
169
|
+
# Like #load_from_hash.
|
170
|
+
# If exists old jobs in Redis but removed from args, destroy old jobs.
|
162
171
|
def self.load_from_hash! hash
|
163
172
|
destroy_removed_jobs(hash.keys)
|
164
173
|
load_from_hash(hash)
|
165
174
|
end
|
166
175
|
|
167
|
-
#
|
168
|
-
#
|
176
|
+
# Load cron jobs from Array.
|
177
|
+
# Input structure should look like:
|
169
178
|
# [
|
170
179
|
# {
|
171
180
|
# 'name' => 'name_of_job',
|
@@ -190,27 +199,27 @@ module Sidekiq
|
|
190
199
|
errors
|
191
200
|
end
|
192
201
|
|
193
|
-
#
|
194
|
-
# If exists old jobs in
|
202
|
+
# Like #load_from_array.
|
203
|
+
# If exists old jobs in Redis but removed from args, destroy old jobs.
|
195
204
|
def self.load_from_array! array
|
196
205
|
job_names = array.map { |job| job["name"] }
|
197
206
|
destroy_removed_jobs(job_names)
|
198
207
|
load_from_array(array)
|
199
208
|
end
|
200
209
|
|
201
|
-
#
|
210
|
+
# Get all cron jobs.
|
202
211
|
def self.all
|
203
212
|
job_hashes = nil
|
204
213
|
Sidekiq.redis do |conn|
|
205
214
|
set_members = conn.smembers(jobs_key)
|
206
|
-
job_hashes = conn.pipelined do
|
215
|
+
job_hashes = conn.pipelined do |pipeline|
|
207
216
|
set_members.each do |key|
|
208
|
-
|
217
|
+
pipeline.hgetall(key)
|
209
218
|
end
|
210
219
|
end
|
211
220
|
end
|
212
221
|
job_hashes.compact.reject(&:empty?).collect do |h|
|
213
|
-
#
|
222
|
+
# No need to fetch missing args from Redis since we just got this hash from there
|
214
223
|
Sidekiq::Cron::Job.new(h.merge(fetch_missing_args: false))
|
215
224
|
end
|
216
225
|
end
|
@@ -224,7 +233,7 @@ module Sidekiq
|
|
224
233
|
end
|
225
234
|
|
226
235
|
def self.find name
|
227
|
-
#
|
236
|
+
# If name is hash try to get name from it.
|
228
237
|
name = name[:name] || name['name'] if name.is_a?(Hash)
|
229
238
|
|
230
239
|
output = nil
|
@@ -233,17 +242,17 @@ module Sidekiq
|
|
233
242
|
output = Job.new conn.hgetall( redis_key(name) )
|
234
243
|
end
|
235
244
|
end
|
236
|
-
output
|
245
|
+
output if output && output.valid?
|
237
246
|
end
|
238
247
|
|
239
|
-
#
|
248
|
+
# Create new instance of cron job.
|
240
249
|
def self.create hash
|
241
250
|
new(hash).save
|
242
251
|
end
|
243
252
|
|
244
|
-
#
|
253
|
+
# Destroy job by name.
|
245
254
|
def self.destroy name
|
246
|
-
#
|
255
|
+
# If name is hash try to get name from it.
|
247
256
|
name = name[:name] || name['name'] if name.is_a?(Hash)
|
248
257
|
|
249
258
|
if job = find(name)
|
@@ -265,22 +274,24 @@ module Sidekiq
|
|
265
274
|
@cron = args["cron"]
|
266
275
|
@description = args["description"] if args["description"]
|
267
276
|
|
268
|
-
#
|
277
|
+
# Get class from klass or class.
|
269
278
|
@klass = args["klass"] || args["class"]
|
270
279
|
|
271
|
-
#
|
280
|
+
# Set status of job.
|
272
281
|
@status = args['status'] || status_from_redis
|
273
282
|
|
274
|
-
#
|
283
|
+
# Set last enqueue time - from args or from existing job.
|
275
284
|
if args['last_enqueue_time'] && !args['last_enqueue_time'].empty?
|
276
285
|
@last_enqueue_time = parse_enqueue_time(args['last_enqueue_time'])
|
277
286
|
else
|
278
287
|
@last_enqueue_time = last_enqueue_time_from_redis
|
279
288
|
end
|
280
289
|
|
281
|
-
#
|
290
|
+
# Get right arguments for job.
|
291
|
+
@symbolize_args = args["symbolize_args"] == true || ("#{args["symbolize_args"]}" =~ (/^(true|t|yes|y|1)$/i)) == 0 || false
|
282
292
|
@args = args["args"].nil? ? [] : parse_args( args["args"] )
|
283
|
-
|
293
|
+
|
294
|
+
@date_as_argument = args["date_as_argument"] == true || ("#{args["date_as_argument"]}" =~ (/^(true|t|yes|y|1)$/i)) == 0 || false
|
284
295
|
|
285
296
|
@active_job = args["active_job"] == true || ("#{args["active_job"]}" =~ (/^(true|t|yes|y|1)$/i)) == 0 || false
|
286
297
|
@active_job_queue_name_prefix = args["queue_name_prefix"]
|
@@ -296,8 +307,8 @@ module Sidekiq
|
|
296
307
|
"args" => @args,
|
297
308
|
}
|
298
309
|
|
299
|
-
#
|
300
|
-
#only if message wasn't specified before
|
310
|
+
# Get right data for message,
|
311
|
+
# only if message wasn't specified before.
|
301
312
|
klass_data = case @klass
|
302
313
|
when Class
|
303
314
|
@klass.get_sidekiq_options
|
@@ -305,21 +316,21 @@ module Sidekiq
|
|
305
316
|
begin
|
306
317
|
Sidekiq::Cron::Support.constantize(@klass).get_sidekiq_options
|
307
318
|
rescue Exception => e
|
308
|
-
#Unknown class
|
319
|
+
# Unknown class
|
309
320
|
{"queue"=>"default"}
|
310
321
|
end
|
311
322
|
end
|
312
323
|
|
313
324
|
message_data = klass_data.merge(message_data)
|
314
|
-
|
315
|
-
#
|
325
|
+
|
326
|
+
# Override queue if setted in config,
|
327
|
+
# only if message is hash - can be string (dumped JSON).
|
316
328
|
if args['queue']
|
317
329
|
@queue = message_data['queue'] = args['queue']
|
318
330
|
else
|
319
331
|
@queue = message_data['queue'] || "default"
|
320
332
|
end
|
321
333
|
|
322
|
-
#dump message as json
|
323
334
|
@message = message_data
|
324
335
|
end
|
325
336
|
|
@@ -381,13 +392,12 @@ module Sidekiq
|
|
381
392
|
conn.lrange(jid_history_key, 0, -1) rescue nil
|
382
393
|
end
|
383
394
|
|
384
|
-
# returns nil if out nil
|
385
395
|
out && out.map do |jid_history_raw|
|
386
396
|
Sidekiq.load_json jid_history_raw
|
387
397
|
end
|
388
398
|
end
|
389
399
|
|
390
|
-
#
|
400
|
+
# Export job data to hash.
|
391
401
|
def to_hash
|
392
402
|
{
|
393
403
|
name: @name,
|
@@ -395,12 +405,14 @@ module Sidekiq
|
|
395
405
|
cron: @cron,
|
396
406
|
description: @description,
|
397
407
|
args: @args.is_a?(String) ? @args : Sidekiq.dump_json(@args || []),
|
408
|
+
date_as_argument: @date_as_argument,
|
398
409
|
message: @message.is_a?(String) ? @message : Sidekiq.dump_json(@message || {}),
|
399
410
|
status: @status,
|
400
411
|
active_job: @active_job,
|
401
412
|
queue_name_prefix: @active_job_queue_name_prefix,
|
402
413
|
queue_name_delimiter: @active_job_queue_name_delimiter,
|
403
414
|
last_enqueue_time: @last_enqueue_time,
|
415
|
+
symbolize_args: @symbolize_args,
|
404
416
|
}
|
405
417
|
end
|
406
418
|
|
@@ -409,7 +421,7 @@ module Sidekiq
|
|
409
421
|
end
|
410
422
|
|
411
423
|
def valid?
|
412
|
-
#
|
424
|
+
# Clear previous errors.
|
413
425
|
@errors = []
|
414
426
|
|
415
427
|
errors << "'name' must be set" if @name.nil? || @name.size == 0
|
@@ -417,7 +429,15 @@ module Sidekiq
|
|
417
429
|
errors << "'cron' must be set"
|
418
430
|
else
|
419
431
|
begin
|
420
|
-
|
432
|
+
c = Fugit.do_parse(@cron)
|
433
|
+
|
434
|
+
# Since `Fugit.do_parse` might yield a Fugit::Duration or an EtOrbi::EoTime
|
435
|
+
# https://github.com/floraison/fugit#fugitparses
|
436
|
+
if c.is_a?(Fugit::Cron)
|
437
|
+
@parsed_cron = c
|
438
|
+
else
|
439
|
+
errors << "'cron' -> #{@cron.inspect} -> not a cron but a #{c.class}"
|
440
|
+
end
|
421
441
|
rescue => e
|
422
442
|
errors << "'cron' -> #{@cron.inspect} -> #{e.class}: #{e.message}"
|
423
443
|
end
|
@@ -438,37 +458,28 @@ module Sidekiq
|
|
438
458
|
end
|
439
459
|
end
|
440
460
|
|
441
|
-
# add job to cron jobs
|
442
|
-
# input:
|
443
|
-
# name: (string) - name of job
|
444
|
-
# cron: (string: '* * * * *' - cron specification when to run job
|
445
|
-
# class: (string|class) - which class to perform
|
446
|
-
# optional input:
|
447
|
-
# queue: (string) - which queue to use for enquing (will override class queue)
|
448
|
-
# args: (array|hash|nil) - arguments for permorm method
|
449
|
-
|
450
461
|
def save
|
451
|
-
#
|
462
|
+
# If job is invalid, return false.
|
452
463
|
return false unless valid?
|
453
464
|
|
454
465
|
Sidekiq.redis do |conn|
|
455
466
|
|
456
|
-
#
|
467
|
+
# Add to set of all jobs
|
457
468
|
conn.sadd self.class.jobs_key, redis_key
|
458
469
|
|
459
|
-
#
|
470
|
+
# Add informations for this job!
|
460
471
|
conn.hmset redis_key, *hash_to_redis(to_hash)
|
461
472
|
|
462
|
-
#
|
473
|
+
# Add information about last time! - don't enque right after scheduler poller starts!
|
463
474
|
time = Time.now.utc
|
464
|
-
conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time).to_s) unless conn.
|
475
|
+
conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time).to_s) unless conn.public_send(REDIS_EXISTS_METHOD, job_enqueued_key)
|
465
476
|
end
|
466
|
-
logger.info { "Cron Jobs -
|
477
|
+
Sidekiq.logger.info { "Cron Jobs - added job with name: #{@name}" }
|
467
478
|
end
|
468
479
|
|
469
480
|
def save_last_enqueue_time
|
470
481
|
Sidekiq.redis do |conn|
|
471
|
-
#
|
482
|
+
# Update last enqueue time.
|
472
483
|
conn.hset redis_key, 'last_enqueue_time', @last_enqueue_time
|
473
484
|
end
|
474
485
|
end
|
@@ -478,44 +489,43 @@ module Sidekiq
|
|
478
489
|
jid: jid,
|
479
490
|
enqueued: @last_enqueue_time
|
480
491
|
}
|
481
|
-
|
492
|
+
|
493
|
+
@history_size ||= (Sidekiq::Options[:cron_history_size] || 10).to_i - 1
|
482
494
|
Sidekiq.redis do |conn|
|
483
495
|
conn.lpush jid_history_key,
|
484
496
|
Sidekiq.dump_json(jid_history)
|
485
|
-
#
|
497
|
+
# Keep only last 10 entries in a fifo manner.
|
486
498
|
conn.ltrim jid_history_key, 0, @history_size
|
487
499
|
end
|
488
500
|
end
|
489
501
|
|
490
|
-
# remove job from cron jobs by name
|
491
|
-
# input:
|
492
|
-
# first arg: name (string) - name of job (must be same - case sensitive)
|
493
502
|
def destroy
|
494
503
|
Sidekiq.redis do |conn|
|
495
|
-
#
|
504
|
+
# Delete from set.
|
496
505
|
conn.srem self.class.jobs_key, redis_key
|
497
506
|
|
498
|
-
#
|
507
|
+
# Delete runned timestamps.
|
499
508
|
conn.del job_enqueued_key
|
500
509
|
|
501
|
-
#
|
510
|
+
# Delete jid_history.
|
502
511
|
conn.del jid_history_key
|
503
512
|
|
504
|
-
#
|
513
|
+
# Delete main job.
|
505
514
|
conn.del redis_key
|
506
515
|
end
|
507
|
-
|
516
|
+
|
517
|
+
Sidekiq.logger.info { "Cron Jobs - deleted job with name: #{@name}" }
|
508
518
|
end
|
509
519
|
|
510
|
-
#
|
520
|
+
# Remove all job from cron.
|
511
521
|
def self.destroy_all!
|
512
522
|
all.each do |job|
|
513
523
|
job.destroy
|
514
524
|
end
|
515
|
-
logger.info { "Cron Jobs - deleted all jobs" }
|
525
|
+
Sidekiq.logger.info { "Cron Jobs - deleted all jobs" }
|
516
526
|
end
|
517
527
|
|
518
|
-
#
|
528
|
+
# Remove "removed jobs" between current jobs and new jobs
|
519
529
|
def self.destroy_removed_jobs new_job_names
|
520
530
|
current_job_names = Sidekiq::Cron::Job.all.map(&:name)
|
521
531
|
removed_job_names = current_job_names - new_job_names
|
@@ -540,7 +550,7 @@ module Sidekiq
|
|
540
550
|
def self.exists? name
|
541
551
|
out = false
|
542
552
|
Sidekiq.redis do |conn|
|
543
|
-
out = conn.
|
553
|
+
out = conn.public_send(REDIS_EXISTS_METHOD, redis_key(name))
|
544
554
|
end
|
545
555
|
out
|
546
556
|
end
|
@@ -556,7 +566,19 @@ module Sidekiq
|
|
556
566
|
private
|
557
567
|
|
558
568
|
def parsed_cron
|
559
|
-
@parsed_cron ||=
|
569
|
+
@parsed_cron ||= begin
|
570
|
+
c = Fugit.parse(@cron)
|
571
|
+
|
572
|
+
# Since `Fugit.parse` might yield a Fugit::Duration or an EtOrbi::EoTime
|
573
|
+
# https://github.com/floraison/fugit#fugitparses
|
574
|
+
if c.is_a?(Fugit::Cron)
|
575
|
+
c
|
576
|
+
else
|
577
|
+
errors << "'cron' -> #{@cron.inspect} -> not a cron but a #{c.class}"
|
578
|
+
end
|
579
|
+
rescue => e
|
580
|
+
errors << "'cron' -> #{@cron.inspect} -> #{e.class}: #{e.message}"
|
581
|
+
end
|
560
582
|
end
|
561
583
|
|
562
584
|
def not_enqueued_after?(time)
|
@@ -564,23 +586,43 @@ module Sidekiq
|
|
564
586
|
end
|
565
587
|
|
566
588
|
# Try parsing inbound args into an array.
|
567
|
-
#
|
568
|
-
# try to load JSON, then failover
|
569
|
-
# to string array.
|
589
|
+
# Args from Redis will be encoded JSON,
|
590
|
+
# try to load JSON, then failover to string array.
|
570
591
|
def parse_args(args)
|
571
592
|
case args
|
572
593
|
when String
|
573
594
|
begin
|
574
|
-
Sidekiq.load_json(args)
|
595
|
+
parsed_args = Sidekiq.load_json(args)
|
596
|
+
symbolize_args? ? symbolize_args(parsed_args) : parsed_args
|
575
597
|
rescue JSON::ParserError
|
576
|
-
[*args]
|
598
|
+
[*args]
|
577
599
|
end
|
578
600
|
when Hash
|
579
|
-
[args]
|
601
|
+
symbolize_args? ? [symbolize_args(args)] : [args]
|
580
602
|
when Array
|
581
|
-
|
603
|
+
symbolize_args? ? symbolize_args(args) : args
|
604
|
+
else
|
605
|
+
[*args]
|
606
|
+
end
|
607
|
+
end
|
608
|
+
|
609
|
+
def symbolize_args?
|
610
|
+
@symbolize_args
|
611
|
+
end
|
612
|
+
|
613
|
+
def symbolize_args(input)
|
614
|
+
if input.is_a?(Array)
|
615
|
+
input.map do |arg|
|
616
|
+
if arg.respond_to?(:symbolize_keys)
|
617
|
+
arg.symbolize_keys
|
618
|
+
else
|
619
|
+
arg
|
620
|
+
end
|
621
|
+
end
|
622
|
+
elsif input.is_a?(Hash) && input.respond_to?(:symbolize_keys)
|
623
|
+
input.symbolize_keys
|
582
624
|
else
|
583
|
-
|
625
|
+
input
|
584
626
|
end
|
585
627
|
end
|
586
628
|
|
@@ -592,29 +634,26 @@ module Sidekiq
|
|
592
634
|
|
593
635
|
def not_past_scheduled_time?(current_time)
|
594
636
|
last_cron_time = parsed_cron.previous_time(current_time).utc
|
595
|
-
# or could it be?
|
596
|
-
#last_cron_time = last_time(current_time)
|
597
637
|
return false if (current_time.to_i - last_cron_time.to_i) > 60
|
598
638
|
true
|
599
639
|
end
|
600
640
|
|
601
|
-
# Redis key for set of all cron jobs
|
641
|
+
# Redis key for set of all cron jobs.
|
602
642
|
def self.jobs_key
|
603
643
|
"cron_jobs"
|
604
644
|
end
|
605
645
|
|
606
|
-
# Redis key for storing one cron job
|
646
|
+
# Redis key for storing one cron job.
|
607
647
|
def self.redis_key name
|
608
648
|
"cron_job:#{name}"
|
609
649
|
end
|
610
650
|
|
611
|
-
# Redis key for storing one cron job
|
651
|
+
# Redis key for storing one cron job.
|
612
652
|
def redis_key
|
613
653
|
self.class.redis_key @name
|
614
654
|
end
|
615
655
|
|
616
|
-
# Redis key for storing one cron job run times
|
617
|
-
# (when poller added job to queue)
|
656
|
+
# Redis key for storing one cron job run times (when poller added job to queue)
|
618
657
|
def self.job_enqueued_key name
|
619
658
|
"cron_job:#{name}:enqueued"
|
620
659
|
end
|
@@ -623,8 +662,6 @@ module Sidekiq
|
|
623
662
|
"cron_job:#{name}:jid_history"
|
624
663
|
end
|
625
664
|
|
626
|
-
# Redis key for storing one cron job run times
|
627
|
-
# (when poller added job to queue)
|
628
665
|
def job_enqueued_key
|
629
666
|
self.class.job_enqueued_key @name
|
630
667
|
end
|
@@ -633,12 +670,10 @@ module Sidekiq
|
|
633
670
|
self.class.jid_history_key @name
|
634
671
|
end
|
635
672
|
|
636
|
-
# Give Hash
|
637
|
-
# returns array for using it for redis.hmset
|
673
|
+
# Give Hash returns array for using it for redis.hmset
|
638
674
|
def hash_to_redis hash
|
639
675
|
hash.inject([]){ |arr,kv| arr + [kv[0], kv[1]] }
|
640
676
|
end
|
641
|
-
|
642
677
|
end
|
643
678
|
end
|
644
679
|
end
|
@@ -1,36 +1,35 @@
|
|
1
|
-
# require cron poller
|
2
1
|
require 'sidekiq/cron/poller'
|
3
2
|
|
4
3
|
# For Cron we need to add some methods to Launcher
|
5
4
|
# so look at the code bellow.
|
6
5
|
#
|
7
|
-
#
|
8
|
-
# adding start and stop commands to launcher
|
6
|
+
# We are creating new cron poller instance and
|
7
|
+
# adding start and stop commands to launcher.
|
9
8
|
module Sidekiq
|
10
9
|
module Cron
|
11
10
|
module Launcher
|
12
|
-
# Add cron poller to launcher
|
11
|
+
# Add cron poller to launcher.
|
13
12
|
attr_reader :cron_poller
|
14
13
|
|
15
|
-
#
|
14
|
+
# Add cron poller and execute normal initialize of Sidekiq launcher.
|
16
15
|
def initialize(options)
|
17
16
|
@cron_poller = Sidekiq::Cron::Poller.new
|
18
17
|
super(options)
|
19
18
|
end
|
20
19
|
|
21
|
-
#
|
20
|
+
# Execute normal run of launcher and run cron poller.
|
22
21
|
def run
|
23
22
|
super
|
24
23
|
cron_poller.start
|
25
24
|
end
|
26
25
|
|
27
|
-
#
|
26
|
+
# Execute normal quiet of launcher and quiet cron poller.
|
28
27
|
def quiet
|
29
28
|
cron_poller.terminate
|
30
29
|
super
|
31
30
|
end
|
32
31
|
|
33
|
-
#
|
32
|
+
# Execute normal stop of launcher and stop cron poller.
|
34
33
|
def stop
|
35
34
|
cron_poller.terminate
|
36
35
|
super
|
@@ -40,7 +39,6 @@ module Sidekiq
|
|
40
39
|
end
|
41
40
|
|
42
41
|
Sidekiq.configure_server do
|
43
|
-
# require Sidekiq original launcher
|
44
42
|
require 'sidekiq/launcher'
|
45
43
|
|
46
44
|
::Sidekiq::Launcher.prepend(Sidekiq::Cron::Launcher)
|
@@ -8,6 +8,8 @@ en:
|
|
8
8
|
EnqueueAll: Enqueue All
|
9
9
|
DeleteAll: Delete All
|
10
10
|
'Cron string': Cron
|
11
|
+
AreYouSureEnqueueCronJobs: Are you sure you want to enqueue ALL cron jobs?
|
12
|
+
AreYouSureEnqueueCronJob: Are you sure you want to enqueue the %{job} cron job?
|
11
13
|
AreYouSureDeleteCronJobs: Are you sure you want to delete ALL cron jobs?
|
12
14
|
AreYouSureDeleteCronJob: Are you sure you want to delete the %{job} cron job?
|
13
15
|
NoCronJobsWereFound: No cron jobs were found
|
@@ -0,0 +1,22 @@
|
|
1
|
+
pt:
|
2
|
+
Job: Tarefa
|
3
|
+
Cron: Cron
|
4
|
+
CronJobs: Tarefas do Cron
|
5
|
+
EnqueueNow: Enfileirar agora
|
6
|
+
EnableAll: Habilitar todos
|
7
|
+
DisableAll: Desabilitar todos
|
8
|
+
EnqueueAll: Enfileirar todos
|
9
|
+
DeleteAll: Excluir todos
|
10
|
+
'Cron string': Cron
|
11
|
+
AreYouSureEnqueueCronJobs: Tem certeza de que deseja enfileirar TODOS as tarefas?
|
12
|
+
AreYouSureEnqueueCronJob: Tem certeza de que deseja enfileirar a tarefa %{job}?
|
13
|
+
AreYouSureDeleteCronJobs: Tem certeza de que deseja excluir TODOS as tarefas?
|
14
|
+
AreYouSureDeleteCronJob: Tem certeza de que deseja excluir a tarefa %{job}?
|
15
|
+
NoCronJobsWereFound: Nenhuma tarefa foi encontrada
|
16
|
+
Enable: Habilitar
|
17
|
+
Disable: Desabilitar
|
18
|
+
'Last enqueued': Último enfileirado
|
19
|
+
disabled: desabilitado
|
20
|
+
enabled: habilitado
|
21
|
+
NoHistoryWereFound: Nenhum histórico foi encontrado
|
22
|
+
Description: Descrição
|