sidekiq-cron 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Changes.md +16 -0
- data/Gemfile +1 -30
- data/README.md +144 -67
- data/Rakefile +0 -18
- data/lib/sidekiq/cron/job.rb +34 -8
- data/lib/sidekiq/cron/locales/en.yml +2 -0
- data/lib/sidekiq/cron/poller.rb +1 -1
- data/lib/sidekiq/cron/version.rb +7 -0
- data/lib/sidekiq/cron/views/cron.erb +4 -4
- data/lib/sidekiq/cron/views/cron.slim +2 -2
- data/lib/sidekiq/cron/views/cron_show.erb +1 -1
- data/lib/sidekiq/cron/views/cron_show.slim +2 -2
- data/lib/sidekiq/cron.rb +1 -0
- data/sidekiq-cron.gemspec +28 -109
- data/test/integration/performance_test.rb +3 -3
- data/test/test_helper.rb +13 -13
- data/test/unit/job_test.rb +102 -0
- data/test/unit/poller_test.rb +1 -1
- data/test/unit/web_extension_test.rb +39 -38
- metadata +30 -158
- data/.travis.yml +0 -18
- data/VERSION +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '091abb12b81574bf5fad5130f4e343aaad6adeceb0daae8c46a6d09dbaa7ee58'
|
4
|
+
data.tar.gz: 1ecbf9ba2fd82ff69a423993e7aa3678e7fabc6fb55e2acea74ec1cb83a8af3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cfd9a8e2efdcf3ae293533421a1c09b7dcc3154e90d749fd3e3a47ccaff6d673daa68877b2ca3b7939139603ee04e816c8c5ae51ef64d818d8d013eff43d9f0
|
7
|
+
data.tar.gz: 0d86e3bb4b06869889934a37ef30f117a4a28769a07e75b3d7547c49d9d8e5dfe4931f608b8b7b18cdc1b70cfdaf6be55aa043844b047b877ff7dfa21271a9f4
|
data/Changes.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
v 1.3.0
|
2
|
+
-------
|
3
|
+
|
4
|
+
- add confirmation dialog when enquing jobs from UI
|
5
|
+
- start to support Sidekiq `average_scheduled_poll_interval` option (replaced `poll_interval`)
|
6
|
+
- enable to use latest fugit to parse cron notation alowing use of natural language (ie `"every 30 minutes"`)
|
7
|
+
- fix deprecation warning for redis 4.6.x
|
8
|
+
- fix different response from Redis#exists in different redis versions
|
9
|
+
- All PRs:
|
10
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/275
|
11
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/287
|
12
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/309
|
13
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/299
|
14
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/314
|
15
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/288
|
16
|
+
|
1
17
|
v 1.2.0
|
2
18
|
-------
|
3
19
|
|
data/Gemfile
CHANGED
@@ -1,32 +1,3 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
gem 'fugit', '~> 1.1'
|
5
|
-
|
6
|
-
group :development do
|
7
|
-
gem 'bundler'
|
8
|
-
gem 'simplecov'
|
9
|
-
|
10
|
-
gem 'redis-namespace', '>= 1.5.2'
|
11
|
-
gem 'shoulda-context'
|
12
|
-
|
13
|
-
gem 'rack'
|
14
|
-
gem 'rack-test'
|
15
|
-
|
16
|
-
gem 'jeweler'
|
17
|
-
|
18
|
-
gem 'minitest'
|
19
|
-
gem 'test-unit'
|
20
|
-
gem 'sdoc' # sdoc -N .
|
21
|
-
|
22
|
-
gem 'slim'
|
23
|
-
gem 'sinatra'
|
24
|
-
|
25
|
-
gem 'mocha'
|
26
|
-
gem 'coveralls'
|
27
|
-
|
28
|
-
gem 'shotgun'
|
29
|
-
|
30
|
-
gem 'guard'
|
31
|
-
gem 'guard-minitest'
|
32
|
-
end
|
3
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,71 +1,68 @@
|
|
1
|
-
Sidekiq-Cron
|
2
|
-
================================================================================================================================================================================================================================================================================================================================================================================================================================================
|
1
|
+
# Sidekiq-Cron
|
3
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/sidekiq-cron.svg)](http://badge.fury.io/rb/sidekiq-cron)
|
4
|
+
[![Build Status](https://github.com/ondrejbartas/sidekiq-cron/workflows/CI/badge.svg?branch=master)](https://github.com/ondrejbartas/sidekiq-cron/actions)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/ondrejbartas/sidekiq-cron/badge.svg?branch=master)](https://coveralls.io/github/ondrejbartas/sidekiq-cron?branch=master)
|
4
6
|
[![Join the chat at https://gitter.im/ondrejbartas/sidekiq-cron](https://badges.gitter.im/ondrejbartas/sidekiq-cron.svg)](https://gitter.im/ondrejbartas/sidekiq-cron?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
5
7
|
|
6
|
-
|
8
|
+
> A scheduling add-on for [Sidekiq](http://sidekiq.org)
|
7
9
|
|
8
|
-
|
10
|
+
🎬 [Introduction video about Sidekiq-Cron by Drifting Ruby](https://www.driftingruby.com/episodes/periodic-tasks-with-sidekiq-cron)
|
9
11
|
|
10
|
-
|
12
|
+
Sidekiq-Cron runs a thread alongside Sidekiq workers to schedule jobs at specified times (using cron notation `* * * * *` parsed by [Fugit](https://github.com/floraison/fugit), more about [cron notation](http://www.nncron.ru/help/EN/working/cron-format.htm).
|
11
13
|
|
12
14
|
Checks for new jobs to schedule every 30 seconds and doesn't schedule the same job multiple times when more than one Sidekiq worker is running.
|
13
15
|
|
14
16
|
Scheduling jobs are added only when at least one Sidekiq process is running, but it is safe to use Sidekiq-Cron in environments where multiple Sidekiq processes or nodes are running.
|
15
17
|
|
16
|
-
If you want to know how scheduling work, check out [under the hood](#under-the-hood)
|
18
|
+
If you want to know how scheduling work, check out [under the hood](#under-the-hood).
|
17
19
|
|
18
|
-
Works with ActiveJob (Rails 4.2+)
|
20
|
+
Works with ActiveJob (Rails 4.2+).
|
19
21
|
|
20
|
-
You don't need Sidekiq PRO, you can use this gem with plain
|
22
|
+
You don't need Sidekiq PRO, you can use this gem with plain Sidekiq.
|
21
23
|
|
22
|
-
Upgrade from <0.6x to 1.0.x
|
23
|
-
---------------------------
|
24
|
+
## Upgrade from <0.6x to 1.0.x
|
24
25
|
|
25
|
-
Please be aware that
|
26
|
+
Please be aware that Sidekiq-Cron < 1.0 was relying on rufus-scheduler < 3.5. Using those older sidekiq-cron with rufus-scheduler >= 3.5 ends up with jobs failing on creation. Sidekiq-cron 1.0 includes a patch that switches from rufus-scheduler to rufus-scheduler's core dependency, fugit.
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
## Changelog
|
29
|
+
|
30
|
+
Before upgrading to new version, please read our [ChangeLog](Changes.md).
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
### Requirements
|
29
35
|
|
30
36
|
- Redis 2.8 or greater is required. (Redis 3.0.3 or greater is recommended for large scale use)
|
31
37
|
- Sidekiq 5, or 4, or 3 and greater is required (for Sidekiq < 4 use version sidekiq-cron 0.3.1)
|
32
38
|
|
33
|
-
|
34
|
-
----------
|
35
|
-
before upgrading to new version, please read:
|
36
|
-
[Change Log](https://github.com/ondrejbartas/sidekiq-cron/blob/master/Changes.md)
|
37
|
-
|
38
|
-
Installation
|
39
|
-
------------
|
39
|
+
Install the gem:
|
40
40
|
|
41
41
|
$ gem install sidekiq-cron
|
42
42
|
|
43
|
-
|
43
|
+
Or add to your `Gemfile` and run `bundle install`:
|
44
44
|
|
45
45
|
gem "sidekiq-cron", "~> 1.1"
|
46
46
|
|
47
|
-
|
48
|
-
Getting Started
|
49
|
-
-----------------
|
50
|
-
|
47
|
+
## Getting Started
|
51
48
|
|
52
49
|
If you are not using Rails, you need to add `require 'sidekiq-cron'` somewhere after `require 'sidekiq'`.
|
53
50
|
|
54
|
-
|
51
|
+
**Job properties:**
|
55
52
|
|
56
53
|
```ruby
|
57
54
|
{
|
58
|
-
'name'
|
59
|
-
'cron'
|
55
|
+
'name' => 'name_of_job', # must be uniq!
|
56
|
+
'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01, 15:01, ... (HH:MM)
|
60
57
|
'class' => 'MyClass',
|
61
|
-
#OPTIONAL
|
58
|
+
# OPTIONAL
|
62
59
|
'queue' => 'name of queue',
|
63
|
-
'args'
|
60
|
+
'args' => '[Array or Hash] of arguments which will be passed to perform method',
|
64
61
|
'date_as_argument' => true, # add the time of execution as last argument of the perform method
|
65
62
|
'active_job' => true, # enqueue job through rails 4.2+ active job interface
|
66
63
|
'queue_name_prefix' => 'prefix', # rails 4.2+ active job queue with prefix
|
67
64
|
'queue_name_delimiter' => '.', # rails 4.2+ active job queue with custom delimiter
|
68
|
-
'description' => 'A sentence describing what work this job performs.'
|
65
|
+
'description' => 'A sentence describing what work this job performs.'
|
69
66
|
}
|
70
67
|
```
|
71
68
|
|
@@ -73,20 +70,27 @@ _Job properties_:
|
|
73
70
|
|
74
71
|
For testing your cron notation you can use [crontab.guru](https://crontab.guru).
|
75
72
|
|
76
|
-
|
73
|
+
Sidekiq-Cron uses [Fugit](https://github.com/floraison/fugit) to parse the cronline.
|
74
|
+
|
77
75
|
If using Rails, this is evaluated against the timezone configured in Rails, otherwise the default is UTC.
|
78
76
|
|
79
77
|
If you want to have your jobs enqueued based on a different time zone you can specify a timezone in the cronline,
|
80
78
|
like this `'0 22 * * 1-5 America/Chicago'`.
|
81
79
|
|
82
|
-
See [rufus-scheduler documentation](https://github.com/jmettraux/rufus-scheduler#a-note-about-timezones) for more information.
|
80
|
+
See [rufus-scheduler documentation](https://github.com/jmettraux/rufus-scheduler#a-note-about-timezones) for more information.
|
81
|
+
|
82
|
+
**NOTE** Rufus scheduler is using Fugit under the hood, so documentation for Rufus Scheduler can help you also.
|
83
83
|
|
84
84
|
### What objects/classes can be scheduled
|
85
|
+
|
85
86
|
#### Sidekiq Worker
|
87
|
+
|
86
88
|
In this example, we are using `HardWorker` which looks like:
|
89
|
+
|
87
90
|
```ruby
|
88
91
|
class HardWorker
|
89
92
|
include Sidekiq::Worker
|
93
|
+
|
90
94
|
def perform(*args)
|
91
95
|
# do something
|
92
96
|
end
|
@@ -94,7 +98,9 @@ end
|
|
94
98
|
```
|
95
99
|
|
96
100
|
#### Active Job Worker
|
97
|
-
|
101
|
+
|
102
|
+
You can schedule `ExampleJob` which looks like:
|
103
|
+
|
98
104
|
```ruby
|
99
105
|
class ExampleJob < ActiveJob::Base
|
100
106
|
queue_as :default
|
@@ -105,11 +111,15 @@ class ExampleJob < ActiveJob::Base
|
|
105
111
|
end
|
106
112
|
```
|
107
113
|
|
114
|
+
For Active jobs you can use `symbolize_args: true` in `Sidekiq::Cron::Job.create` or in Hash configuration,
|
115
|
+
which will ensure that arguments you are passing to it will be symbolized when passed back to `perform` method in worker.
|
116
|
+
|
108
117
|
#### Adding Cron job:
|
109
|
-
```ruby
|
110
118
|
|
119
|
+
```ruby
|
111
120
|
class HardWorker
|
112
121
|
include Sidekiq::Worker
|
122
|
+
|
113
123
|
def perform(name, count)
|
114
124
|
# do something
|
115
125
|
end
|
@@ -130,16 +140,15 @@ else
|
|
130
140
|
puts job.errors
|
131
141
|
end
|
132
142
|
|
133
|
-
#or simple
|
134
|
-
|
143
|
+
# or simple
|
135
144
|
unless job.save
|
136
|
-
puts job.errors #will return array of errors
|
145
|
+
puts job.errors # will return array of errors
|
137
146
|
end
|
138
147
|
```
|
139
148
|
|
140
149
|
Load more jobs from hash:
|
141
|
-
```ruby
|
142
150
|
|
151
|
+
```ruby
|
143
152
|
hash = {
|
144
153
|
'name_of_job' => {
|
145
154
|
'class' => 'MyClass',
|
@@ -156,6 +165,7 @@ Sidekiq::Cron::Job.load_from_hash hash
|
|
156
165
|
```
|
157
166
|
|
158
167
|
Load more jobs from array:
|
168
|
+
|
159
169
|
```ruby
|
160
170
|
array = [
|
161
171
|
{
|
@@ -174,17 +184,17 @@ array = [
|
|
174
184
|
Sidekiq::Cron::Job.load_from_array array
|
175
185
|
```
|
176
186
|
|
177
|
-
Bang-suffixed methods will remove jobs that are not present in the given hash/array,
|
178
|
-
update jobs that have the same names, and create new ones when the names are previously unknown.
|
187
|
+
Bang-suffixed methods will remove jobs that are not present in the given hash/array, update jobs that have the same names, and create new ones when the names are previously unknown.
|
179
188
|
|
180
189
|
```ruby
|
181
190
|
Sidekiq::Cron::Job#load_from_hash! hash
|
182
191
|
Sidekiq::Cron::Job#load_from_array! array
|
183
192
|
```
|
184
193
|
|
185
|
-
|
194
|
+
Or from YAML (same notation as Resque-scheduler):
|
195
|
+
|
186
196
|
```yaml
|
187
|
-
#config/schedule.yml
|
197
|
+
# config/schedule.yml
|
188
198
|
|
189
199
|
my_first_job:
|
190
200
|
cron: "*/5 * * * *"
|
@@ -200,7 +210,7 @@ second_job:
|
|
200
210
|
```
|
201
211
|
|
202
212
|
```ruby
|
203
|
-
#initializers/sidekiq.rb
|
213
|
+
# config/initializers/sidekiq.rb
|
204
214
|
schedule_file = "config/schedule.yml"
|
205
215
|
|
206
216
|
if File.exist?(schedule_file) && Sidekiq.server?
|
@@ -208,56 +218,60 @@ if File.exist?(schedule_file) && Sidekiq.server?
|
|
208
218
|
end
|
209
219
|
```
|
210
220
|
|
211
|
-
|
221
|
+
Or you can use for loading jobs from yml file [sidekiq-cron-tasks](https://github.com/coverhound/sidekiq-cron-tasks) which will add rake task `bundle exec rake sidekiq_cron:load` to your rails application.
|
222
|
+
|
223
|
+
### Finding jobs
|
212
224
|
|
213
|
-
#### Finding jobs
|
214
225
|
```ruby
|
215
|
-
#return array of all jobs
|
226
|
+
# return array of all jobs
|
216
227
|
Sidekiq::Cron::Job.all
|
217
228
|
|
218
|
-
#return one job by its unique name - case sensitive
|
229
|
+
# return one job by its unique name - case sensitive
|
219
230
|
Sidekiq::Cron::Job.find "Job Name"
|
220
231
|
|
221
|
-
#return one job by its unique name - you can use hash with 'name' key
|
232
|
+
# return one job by its unique name - you can use hash with 'name' key
|
222
233
|
Sidekiq::Cron::Job.find name: "Job Name"
|
223
234
|
|
224
|
-
#if job can't be found nil is returned
|
235
|
+
# if job can't be found nil is returned
|
225
236
|
```
|
226
237
|
|
227
|
-
|
238
|
+
### Destroy jobs:
|
239
|
+
|
228
240
|
```ruby
|
229
|
-
#
|
241
|
+
# destroy all jobs
|
230
242
|
Sidekiq::Cron::Job.destroy_all!
|
231
243
|
|
232
|
-
#destroy job by its name
|
244
|
+
# destroy job by its name
|
233
245
|
Sidekiq::Cron::Job.destroy "Job Name"
|
234
246
|
|
235
|
-
#destroy found job
|
247
|
+
# destroy found job
|
236
248
|
Sidekiq::Cron::Job.find('Job name').destroy
|
237
249
|
```
|
238
250
|
|
239
|
-
|
251
|
+
### Work with job:
|
252
|
+
|
240
253
|
```ruby
|
241
254
|
job = Sidekiq::Cron::Job.find('Job name')
|
242
255
|
|
243
|
-
#disable cron scheduling
|
256
|
+
# disable cron scheduling
|
244
257
|
job.disable!
|
245
258
|
|
246
|
-
#enable cron scheduling
|
259
|
+
# enable cron scheduling
|
247
260
|
job.enable!
|
248
261
|
|
249
|
-
#get status of job:
|
262
|
+
# get status of job:
|
250
263
|
job.status
|
251
264
|
# => enabled/disabled
|
252
265
|
|
253
|
-
#enqueue job right now!
|
266
|
+
# enqueue job right now!
|
254
267
|
job.enque!
|
255
268
|
```
|
256
269
|
|
257
|
-
How to start scheduling?
|
270
|
+
### How to start scheduling?
|
271
|
+
|
258
272
|
Just start Sidekiq workers by running:
|
259
273
|
|
260
|
-
sidekiq
|
274
|
+
$ sidekiq
|
261
275
|
|
262
276
|
### Web UI for Cron Jobs
|
263
277
|
|
@@ -270,7 +284,7 @@ With this, you will get:
|
|
270
284
|
### Forking Processes
|
271
285
|
|
272
286
|
If you're using a forking web server like Unicorn you may run into an issue where the Redis connection is used
|
273
|
-
before the process forks, causing the following exception
|
287
|
+
before the process forks, causing the following exception:
|
274
288
|
|
275
289
|
Redis::InheritedError: Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.
|
276
290
|
|
@@ -286,37 +300,100 @@ Sidekiq.configure_server do |config|
|
|
286
300
|
end
|
287
301
|
```
|
288
302
|
|
289
|
-
|
303
|
+
**NOTE** This API is only available in Sidekiq 3.x.
|
304
|
+
|
305
|
+
## Tests in Sidekiq-Cron
|
306
|
+
|
307
|
+
If you need to check code of sidekiq-cron run `rake test` in this repository.
|
290
308
|
|
291
309
|
## Under the hood
|
292
310
|
|
293
311
|
When you start the Sidekiq process, it starts one thread with `Sidekiq::Poller` instance, which perform the adding of scheduled jobs to queues, retries etc.
|
294
312
|
|
295
|
-
Sidekiq-Cron adds itself into this start procedure and starts another thread with `Sidekiq::Cron::Poller` which checks all enabled Sidekiq cron jobs every
|
313
|
+
Sidekiq-Cron adds itself into this start procedure and starts another thread with `Sidekiq::Cron::Poller` which checks all enabled Sidekiq cron jobs every 30 seconds, if they should be added to queue (their cronline matches time of check).
|
296
314
|
|
297
315
|
Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can change it by setting:
|
298
|
-
|
316
|
+
|
317
|
+
```ruby
|
318
|
+
# For Sidekiq >= 3.4
|
319
|
+
Sidekiq.options[:average_scheduled_poll_interval] = 10
|
320
|
+
|
321
|
+
# For older versions of Sidekiq
|
299
322
|
Sidekiq.options[:poll_interval] = 10
|
300
323
|
```
|
301
324
|
|
302
325
|
Sidekiq-Cron is safe to use with multiple sidekiq processes or nodes. It uses a Redis sorted set to determine that only the first process who asks can enqueue scheduled jobs into the queue.
|
303
326
|
|
304
327
|
## Thanks to
|
328
|
+
* [@284km](https://github.com/284km)
|
305
329
|
* [@7korobi](https://github.com/7korobi)
|
330
|
+
* [@adrianobarroso](https://github.com/adrianobarroso])
|
331
|
+
* [@alexeyramazanov](https://github.com/alexeyramazanov)
|
306
332
|
* [@antulik](https://github.com/antulik)
|
333
|
+
* [@arthurbryant](https://github.com/arthurbryant)
|
334
|
+
* [@cabello](https://github.com/cabello)
|
335
|
+
* [@camkidman](https://github.com/camkidman)
|
336
|
+
* [@cgunther](https://github.com/cgunther)
|
337
|
+
* [@chuchuva](https://github.com/chuchuva)
|
338
|
+
* [@corroded](https://github.com/corroded)
|
339
|
+
* [@D1ceWard](https://github.com/D1ceWard])
|
340
|
+
* [@davidtrogers](https://github.com/davidtrogers)
|
341
|
+
* [@denispeplin](https://github.com/denispeplin)
|
342
|
+
* [@dwarburt](https://github.com/dwarburt)
|
343
|
+
* [@Envek](https://github.com/Envek)
|
344
|
+
* [@Eunix](https://github.com/Eunix)
|
307
345
|
* [@felixbuenemann](https://github.com/felixbuenemann)
|
346
|
+
* [@film42](https://github.com/film42])
|
347
|
+
* [@giriss](https://github.com/giriss)
|
348
|
+
* [@gitter](https://github.com/gitter)
|
308
349
|
* [@gstark](https://github.com/gstark)
|
350
|
+
* [@h0jeZvgoxFepBQ2C](https://github.com/h0jeZvgoxFepBQ2C)
|
351
|
+
* [@incubus](https://github.com/incubus)
|
352
|
+
* [@jack0pan](https://github.com/jack0pan)
|
353
|
+
* [@jmettraux](https://github.com/jmettraux)
|
354
|
+
* [@johnathanludwig](https://github.com/johnathanludwig)
|
355
|
+
* [@joshuacronemeyer](https://github.com/joshuacronemeyer)
|
356
|
+
* [@jpserra](https://github.com/jpserra)
|
357
|
+
* [@Junyulive](https://github.com/Junyulive)
|
358
|
+
* [@le0pard](https://github.com/le0pard)
|
359
|
+
* [@lepfhty](https://github.com/lepfhty)
|
360
|
+
* [@macool](https://github.com/macool)
|
361
|
+
* [@masayukioguni](https://github.com/masayukioguni)
|
362
|
+
* [@matsimitsu](https://github.com/matsimitsu)
|
363
|
+
* [@merrington](https://github.com/merrington)
|
364
|
+
* [@MikeRogers0](https://github.com/MikeRogers0)
|
365
|
+
* [@MMartyn](https://github.com/MMartyn)
|
366
|
+
* [@mrchucho](https://github.com/mrchucho)
|
367
|
+
* [@n00dle](https://github.com/n00dle)
|
368
|
+
* [@ngouy](https://github.com/ngouy)
|
369
|
+
* [@nhoffmann](https://github.com/nhoffmann)
|
370
|
+
* [@nicolasleger](https://github.com/nicolasleger)
|
371
|
+
* [@nikolai-b](https://github.com/nikolai-b)
|
372
|
+
* [@oivoodoo](https://github.com/oivoodoo)
|
373
|
+
* [@paniko0](https://github.com/paniko0)
|
374
|
+
* [@petergoldstein](https://github.com/petergoldstein)
|
309
375
|
* [@RajRoR](https://github.com/RajRoR)
|
376
|
+
* [@rmm5t](https://github.com/rmm5t)
|
310
377
|
* [@romeuhcf](https://github.com/romeuhcf)
|
378
|
+
* [@rylwin](https://github.com/rylwin)
|
379
|
+
* [@ryohashimoto](https://github.com/ryohashimoto)
|
380
|
+
* [@safeforge](https://github.com/safeforge)
|
311
381
|
* [@siruguri](https://github.com/siruguri)
|
312
382
|
* [@Soliah](https://github.com/Soliah)
|
383
|
+
* [@spk](https://github.com/spk)
|
313
384
|
* [@stephankaag](https://github.com/stephankaag)
|
385
|
+
* [@stormsilver](https://github.com/stormsilver)
|
314
386
|
* [@sue445](https://github.com/sue445)
|
315
387
|
* [@sylg](https://github.com/sylg)
|
388
|
+
* [@tai2](https://github.com/tai2)
|
389
|
+
* [@tfluehmann](https://github.com/tfluehmann)
|
390
|
+
* [@timminkov](https://github.com/timminkov)
|
391
|
+
* [@tisba](https://github.com/tisba)
|
316
392
|
* [@tmeinlschmidt](https://github.com/tmeinlschmidt)
|
393
|
+
* [@tomprats](https://github.com/tomprats)
|
394
|
+
* [@zedtux](https://github.com/zedtux)
|
317
395
|
* [@zerobearing2](https://github.com/zerobearing2)
|
318
396
|
|
319
|
-
|
320
397
|
## Contributing to sidekiq-cron
|
321
398
|
|
322
399
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
@@ -329,4 +406,4 @@ Sidekiq-Cron is safe to use with multiple sidekiq processes or nodes. It uses a
|
|
329
406
|
|
330
407
|
## Copyright
|
331
408
|
|
332
|
-
Copyright (c) 2013 Ondrej Bartas. See LICENSE.txt for further details.
|
409
|
+
Copyright (c) 2013 Ondrej Bartas. See [LICENSE](LICENSE.txt) for further details.
|
data/Rakefile
CHANGED
@@ -13,26 +13,8 @@ rescue Bundler::BundlerError => e
|
|
13
13
|
end
|
14
14
|
require 'rake'
|
15
15
|
|
16
|
-
require 'jeweler'
|
17
|
-
Jeweler::Tasks.new do |gem|
|
18
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
19
|
-
gem.name = "sidekiq-cron"
|
20
|
-
gem.homepage = "http://github.com/ondrejbartas/sidekiq-cron"
|
21
|
-
gem.license = "MIT"
|
22
|
-
gem.summary = %Q{Sidekiq Cron helps to add repeated scheduled jobs}
|
23
|
-
gem.description = %Q{Enables to set jobs to be run in specified time (using CRON notation)}
|
24
|
-
gem.email = "ondrej@bartas.cz"
|
25
|
-
gem.authors = ["Ondrej Bartas"]
|
26
|
-
# dependencies defined in Gemfile
|
27
|
-
end
|
28
|
-
Jeweler::RubygemsDotOrgTasks.new
|
29
|
-
|
30
16
|
#TESTING
|
31
17
|
|
32
|
-
task :doc do
|
33
|
-
system 'sdoc -N .'
|
34
|
-
end
|
35
|
-
|
36
18
|
require 'rake/testtask'
|
37
19
|
task :default => :test
|
38
20
|
|
data/lib/sidekiq/cron/job.rb
CHANGED
@@ -14,6 +14,9 @@ module Sidekiq
|
|
14
14
|
REMEMBER_THRESHOLD = 24 * 60 * 60
|
15
15
|
LAST_ENQUEUE_TIME_FORMAT = '%Y-%m-%d %H:%M:%S %z'
|
16
16
|
|
17
|
+
# Use the exists? method if we're on a newer version of redis.
|
18
|
+
REDIS_EXISTS_METHOD = Gem.loaded_specs['redis'].version < Gem::Version.new('4.2') ? :exists : :exists?
|
19
|
+
|
17
20
|
#crucial part of whole enquing job
|
18
21
|
def should_enque? time
|
19
22
|
enqueue = false
|
@@ -203,9 +206,9 @@ module Sidekiq
|
|
203
206
|
job_hashes = nil
|
204
207
|
Sidekiq.redis do |conn|
|
205
208
|
set_members = conn.smembers(jobs_key)
|
206
|
-
job_hashes = conn.pipelined do
|
209
|
+
job_hashes = conn.pipelined do |pipeline|
|
207
210
|
set_members.each do |key|
|
208
|
-
|
211
|
+
pipeline.hgetall(key)
|
209
212
|
end
|
210
213
|
end
|
211
214
|
end
|
@@ -233,7 +236,7 @@ module Sidekiq
|
|
233
236
|
output = Job.new conn.hgetall( redis_key(name) )
|
234
237
|
end
|
235
238
|
end
|
236
|
-
output
|
239
|
+
output if output && output.valid?
|
237
240
|
end
|
238
241
|
|
239
242
|
# create new instance of cron job
|
@@ -279,6 +282,7 @@ module Sidekiq
|
|
279
282
|
end
|
280
283
|
|
281
284
|
#get right arguments for job
|
285
|
+
@symbolize_args = args["symbolize_args"] == true || ("#{args["symbolize_args"]}" =~ (/^(true|t|yes|y|1)$/i)) == 0 || false
|
282
286
|
@args = args["args"].nil? ? [] : parse_args( args["args"] )
|
283
287
|
@args += [Time.now.to_f] if args["date_as_argument"]
|
284
288
|
|
@@ -401,6 +405,7 @@ module Sidekiq
|
|
401
405
|
queue_name_prefix: @active_job_queue_name_prefix,
|
402
406
|
queue_name_delimiter: @active_job_queue_name_delimiter,
|
403
407
|
last_enqueue_time: @last_enqueue_time,
|
408
|
+
symbolize_args: @symbolize_args,
|
404
409
|
}
|
405
410
|
end
|
406
411
|
|
@@ -461,7 +466,7 @@ module Sidekiq
|
|
461
466
|
|
462
467
|
#add information about last time! - don't enque right after scheduler poller starts!
|
463
468
|
time = Time.now.utc
|
464
|
-
conn.zadd(job_enqueued_key, time.to_f.to_s, formated_last_time(time).to_s) unless conn.
|
469
|
+
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
470
|
end
|
466
471
|
logger.info { "Cron Jobs - add job with name: #{@name}" }
|
467
472
|
end
|
@@ -540,7 +545,7 @@ module Sidekiq
|
|
540
545
|
def self.exists? name
|
541
546
|
out = false
|
542
547
|
Sidekiq.redis do |conn|
|
543
|
-
out = conn.
|
548
|
+
out = conn.public_send(REDIS_EXISTS_METHOD, redis_key(name))
|
544
549
|
end
|
545
550
|
out
|
546
551
|
end
|
@@ -571,19 +576,40 @@ module Sidekiq
|
|
571
576
|
case args
|
572
577
|
when String
|
573
578
|
begin
|
574
|
-
Sidekiq.load_json(args)
|
579
|
+
parsed_args = Sidekiq.load_json(args)
|
580
|
+
symbolize_args? ? symbolize_args(parsed_args) : parsed_args
|
575
581
|
rescue JSON::ParserError
|
576
582
|
[*args] # cast to string array
|
577
583
|
end
|
578
584
|
when Hash
|
579
|
-
[args]
|
585
|
+
symbolize_args? ? [symbolize_args(args)] : [args]
|
580
586
|
when Array
|
581
|
-
|
587
|
+
symbolize_args? ? symbolize_args(args) : args
|
582
588
|
else
|
583
589
|
[*args] # cast to string array
|
584
590
|
end
|
585
591
|
end
|
586
592
|
|
593
|
+
def symbolize_args?
|
594
|
+
@symbolize_args
|
595
|
+
end
|
596
|
+
|
597
|
+
def symbolize_args(input)
|
598
|
+
if input.is_a?(Array)
|
599
|
+
input.map do |arg|
|
600
|
+
if arg.respond_to?(:symbolize_keys)
|
601
|
+
arg.symbolize_keys
|
602
|
+
else
|
603
|
+
arg
|
604
|
+
end
|
605
|
+
end
|
606
|
+
elsif input.is_a?(Hash) && input.respond_to?(:symbolize_keys)
|
607
|
+
input.symbolize_keys
|
608
|
+
else
|
609
|
+
input
|
610
|
+
end
|
611
|
+
end
|
612
|
+
|
587
613
|
def parse_enqueue_time(timestamp)
|
588
614
|
DateTime.strptime(timestamp, LAST_ENQUEUE_TIME_FORMAT).to_time.utc
|
589
615
|
rescue ArgumentError
|
@@ -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
|
data/lib/sidekiq/cron/poller.rb
CHANGED