sidekiq-cron 0.6.3 → 1.4.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/Changes.md +102 -50
- data/Gemfile +1 -30
- data/README.md +162 -103
- data/Rakefile +3 -42
- data/lib/sidekiq/cron/job.rb +117 -41
- data/lib/sidekiq/cron/launcher.rb +34 -40
- data/lib/sidekiq/cron/locales/de.yml +2 -2
- data/lib/sidekiq/cron/locales/en.yml +6 -2
- data/lib/sidekiq/cron/locales/ja.yml +18 -0
- data/lib/sidekiq/cron/locales/ru.yml +2 -2
- data/lib/sidekiq/cron/locales/zh-CN.yml +19 -0
- data/lib/sidekiq/cron/poller.rb +7 -5
- data/lib/sidekiq/cron/version.rb +7 -0
- data/lib/sidekiq/cron/views/cron.erb +38 -28
- data/lib/sidekiq/cron/views/cron_show.erb +88 -0
- data/lib/sidekiq/cron/web.rb +1 -7
- data/lib/sidekiq/cron/web_extension.rb +14 -7
- data/sidekiq-cron.gemspec +19 -103
- data/test/integration/performance_test.rb +7 -10
- data/test/test_helper.rb +27 -29
- data/test/unit/job_test.rb +171 -18
- data/test/unit/poller_test.rb +22 -25
- data/test/unit/web_extension_test.rb +57 -38
- metadata +34 -179
- data/.document +0 -5
- data/.travis.yml +0 -19
- data/Dockerfile +0 -32
- data/VERSION +0 -1
- data/config.ru +0 -14
- data/docker-compose.yml +0 -21
- data/examples/web-cron-ui.png +0 -0
- data/lib/sidekiq/cron/views/cron.slim +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 437dc35edb85224f5e77eaa73be4adac923adb313f755f3029a4037e92a9c523
|
4
|
+
data.tar.gz: 517c8dd23943edb6c1e6e3059b4b6f7044ff85d13594447dbb097ff7438afc63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d943877a3c9577b060ccbc86fca6e256ac6e12e7ab4ef5428091960d82d119b8087264b3fd20afcd2a191dc722f42deab5701557aa5d1fd9e0f2cfe10357b26
|
7
|
+
data.tar.gz: 39f3b04c168c250f0273796fb1c6f20947114d92030d60fed74d2c5087ee401b35f0b3e1fdea00a6c7eac9116d76204ce439dae7a5ba965b60978034ae472d38
|
data/Changes.md
CHANGED
@@ -1,50 +1,102 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
-
|
18
|
-
-
|
19
|
-
-
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
## 1.4.0
|
6
|
+
|
7
|
+
- Fix buttons order in job show view (https://github.com/ondrejbartas/sidekiq-cron/pull/302)
|
8
|
+
- Dark Mode support in UI (https://github.com/ondrejbartas/sidekiq-cron/pull/317/282)
|
9
|
+
- Remove invocation of deprecated Redis functionality (https://github.com/ondrejbartas/sidekiq-cron/pull/318)
|
10
|
+
- Internal code cleanup (https://github.com/ondrejbartas/sidekiq-cron/pull/317)
|
11
|
+
- Optimize gem size (https://github.com/ondrejbartas/sidekiq-cron/pull/322)
|
12
|
+
- Fix "Show All" button on cron jobs view with Sidekiq 6.3.0+ (https://github.com/ondrejbartas/sidekiq-cron/pull/321)
|
13
|
+
- Documentation updates
|
14
|
+
|
15
|
+
## 1.3.0
|
16
|
+
|
17
|
+
- Add confirmation dialog when enquing jobs from UI
|
18
|
+
- Start to support Sidekiq `average_scheduled_poll_interval` option (replaced `poll_interval`)
|
19
|
+
- Enable to use latest fugit to parse cron notation alowing use of natural language (ie `"every 30 minutes"`)
|
20
|
+
- Fix deprecation warning for Redis 4.6.x
|
21
|
+
- Fix different response from Redis#exists in different Redis versions
|
22
|
+
- All PRs:
|
23
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/275
|
24
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/287
|
25
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/309
|
26
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/299
|
27
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/314
|
28
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/288
|
29
|
+
|
30
|
+
## 1.2.0
|
31
|
+
|
32
|
+
- Updated readme
|
33
|
+
- Fix problem with Sidekiq::Launcher and requiring it when not needed
|
34
|
+
- Better patching of Sidekiq::Launcher
|
35
|
+
- Fixed Dockerfile
|
36
|
+
|
37
|
+
## 1.1.0
|
38
|
+
|
39
|
+
- Updated readme
|
40
|
+
- Fix unit tests - changed argument error when getting invalid cron format
|
41
|
+
- When fallbacking old job enqueued time use `Time.parse` without format (so ruby can decide best method to parse it)
|
42
|
+
- Add option `date_as_argument` which will add to your job arguments on last place `Time.now.to_f` when it was eneuqued
|
43
|
+
- Add option `description` which will allow you to add notes to your jobs so in web view you can see it
|
44
|
+
- Fixed translations
|
45
|
+
|
46
|
+
## 1.0.4
|
47
|
+
|
48
|
+
- Fix problem with upgrading to 1.0.x - parsing last enqued time didn't count with old time format stored in Redis
|
49
|
+
|
50
|
+
## 1.0.0
|
51
|
+
|
52
|
+
- Use [fugit](https://github.com/floraison/fugit) instead of [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) - API of cron didn't change (rufus scheduler is using fugit)
|
53
|
+
- Better working with Timezones
|
54
|
+
- Translations for JA, zh-CN
|
55
|
+
- Cron without timezone are considered as UTC, to add Timezone to cron use format `* * * * * Europe/Berlin`
|
56
|
+
- Be aware that this release can change when your jobs are enqueued (for me it didn't change but it is in one project, in other it can shift by different timezone setup)
|
57
|
+
|
58
|
+
## 0.6.0
|
59
|
+
|
60
|
+
- Set poller to check jobs every 30s by default (possible to override by `Sidekiq.options[:poll_interval] = 10`)
|
61
|
+
- Add group actions (enqueue, enable, disable, delete) all in web view
|
62
|
+
- Fix poller to enqueu all jobs in poll start time
|
63
|
+
- Add performance test for enqueue of jobs (10 000 jobs in less than 19s)
|
64
|
+
- Fix problem with default queue
|
65
|
+
- Remove redis-namespace from dependencies
|
66
|
+
- Update ruby versions in travis
|
67
|
+
|
68
|
+
## 0.5.0
|
69
|
+
|
70
|
+
- Add Docker support
|
71
|
+
- All crons are now evaluated in UTC
|
72
|
+
- Fix rufus scheduler & timezones problems
|
73
|
+
- Add support for Sidekiq 4.2.1
|
74
|
+
- Fix readme
|
75
|
+
- Add Russian locale
|
76
|
+
- User Rack.env in tests
|
77
|
+
- Faster enqueue of jobs
|
78
|
+
- Permit to use ActiveJob::Base.queue_name_delimiter
|
79
|
+
- Fix problem with multiple times enqueue #84
|
80
|
+
- Fix problem with enqueue of unknown class
|
81
|
+
|
82
|
+
## 0.4.0
|
83
|
+
|
84
|
+
- Enable to work with Sidekiq >= 4.0.0
|
85
|
+
- Fix readme
|
86
|
+
|
87
|
+
## 0.3.1
|
88
|
+
|
89
|
+
- Add CSRF tags to forms so it will work with Sidekiq >= 3.4.2
|
90
|
+
- Remove Tilt dependency
|
91
|
+
|
92
|
+
## 0.3.0
|
93
|
+
|
94
|
+
- Suport for Active Job
|
95
|
+
- Sidekiq cron web ui needs to be loaded by: require 'sidekiq/cron/web'
|
96
|
+
- Add load_from_hash! and load_from_array! which cleanup jobs before adding new ones
|
97
|
+
|
98
|
+
## 0.1.1
|
99
|
+
|
100
|
+
- Add Web front-end with enabled/disable job, enqueue now, delete job
|
101
|
+
- Add cron poller - enqueue cron jobs
|
102
|
+
- Add cron job - save all needed data to Redis
|
data/Gemfile
CHANGED
@@ -1,32 +1,3 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
gem 'rufus-scheduler', '>= 3.3.0'
|
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,81 +1,113 @@
|
|
1
|
-
Sidekiq-Cron
|
2
|
-
================================================================================================================================================================================================================================================================================================================================================================================================================================================
|
1
|
+
# Sidekiq-Cron
|
3
2
|
|
3
|
+
[](https://badge.fury.io/rb/sidekiq-cron)
|
4
|
+
[](https://github.com/ondrejbartas/sidekiq-cron/actions)
|
5
|
+
[](https://coveralls.io/github/ondrejbartas/sidekiq-cron?branch=master)
|
4
6
|
[](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](https://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)).
|
11
13
|
|
12
|
-
Checks for new jobs to schedule every
|
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
|
-
Scheduling jobs are added only when at least one Sidekiq process is running.
|
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
|
-
|
23
|
-
-----------------
|
24
|
+
## Upgrade from < 0.6 to 1.0
|
24
25
|
|
25
|
-
-
|
26
|
-
- Sidekiq 5, or 4, or 3 and greater is required (for Sidekiq < 4 use version sidekiq-cron 0.3.1)
|
26
|
+
Please be aware that Sidekiq-Cron < 1.0 was relying on rufus-scheduler < 3.5. Using those older versions 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.
|
27
27
|
|
28
|
-
|
29
|
-
----------
|
30
|
-
before upgrading to new version, please read:
|
31
|
-
[Change Log](https://github.com/ondrejbartas/sidekiq-cron/blob/master/Changes.md)
|
28
|
+
## Changelog
|
32
29
|
|
33
|
-
|
34
|
-
------------
|
30
|
+
Before upgrading to a new version, please read our [Changelog](Changes.md).
|
35
31
|
|
36
|
-
|
32
|
+
## Installation
|
37
33
|
|
38
|
-
|
34
|
+
### Requirements
|
39
35
|
|
40
|
-
|
36
|
+
- Redis 2.8 or greater is required (Redis 3.0.3 or greater is recommended for large scale use)
|
37
|
+
- Sidekiq 4.2 or greater is required (for Sidekiq < 4 use version sidekiq-cron 0.3.1)
|
41
38
|
|
39
|
+
Install the gem:
|
42
40
|
|
43
|
-
|
44
|
-
|
41
|
+
```
|
42
|
+
$ gem install sidekiq-cron
|
43
|
+
```
|
44
|
+
|
45
|
+
Or add to your `Gemfile` and run `bundle install`:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
gem "sidekiq-cron", "~> 1.3"
|
49
|
+
```
|
45
50
|
|
51
|
+
**NOTE** If you are not using Rails, you need to add `require 'sidekiq-cron'` somewhere after `require 'sidekiq'`.
|
46
52
|
|
47
|
-
|
53
|
+
## Getting Started
|
48
54
|
|
49
|
-
|
55
|
+
**Job properties:**
|
50
56
|
|
51
57
|
```ruby
|
52
58
|
{
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
'name' => 'name_of_job', # must be uniq!
|
60
|
+
'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01, 15:01, ... (HH:MM)
|
61
|
+
'class' => 'MyClass',
|
62
|
+
# OPTIONAL
|
63
|
+
'queue' => 'name of queue',
|
64
|
+
'args' => '[Array or Hash] of arguments which will be passed to perform method',
|
65
|
+
'date_as_argument' => true, # add the time of execution as last argument of the perform method
|
66
|
+
'active_job' => true, # enqueue job through rails 4.2+ active job interface
|
67
|
+
'queue_name_prefix' => 'prefix', # rails 4.2+ active job queue with prefix
|
68
|
+
'queue_name_delimiter' => '.', # rails 4.2+ active job queue with custom delimiter
|
69
|
+
'description' => 'A sentence describing what work this job performs.'
|
70
|
+
'status' => 'disabled' # default: enabled
|
62
71
|
}
|
63
72
|
```
|
64
73
|
|
65
|
-
### Time, cron and
|
74
|
+
### Time, cron and Sidekiq-Cron
|
75
|
+
|
76
|
+
For testing your cron notation you can use [crontab.guru](https://crontab.guru).
|
77
|
+
|
78
|
+
Sidekiq-Cron uses [Fugit](https://github.com/floraison/fugit) to parse the cronline. So please, check Fugit documentation for further information about allowed formats.
|
79
|
+
|
80
|
+
If using Rails, this is evaluated against the timezone configured in Rails, otherwise the default is UTC.
|
66
81
|
|
67
|
-
sidekiq-cron uses [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) to parse the cronline.
|
68
|
-
By default, the timezone this is evaluated against UTC.
|
69
82
|
If you want to have your jobs enqueued based on a different time zone you can specify a timezone in the cronline,
|
70
83
|
like this `'0 22 * * 1-5 America/Chicago'`.
|
71
|
-
|
84
|
+
|
85
|
+
#### Second-precision (sub-minute) cronlines
|
86
|
+
|
87
|
+
In addition to the standard 5-parameter cronline format, sidekiq-cron supports scheduling jobs with second-precision using a modified 6-parameter cronline format:
|
88
|
+
|
89
|
+
`Seconds Minutes Hours Days Months DayOfWeek`
|
90
|
+
|
91
|
+
For example: `"*/30 * * * * *"` would schedule a job to run every 30 seconds.
|
92
|
+
|
93
|
+
Note that if you plan to schedule jobs with second precision you may need to override the default schedule poll interval so it is lower than the interval of your jobs:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
Sidekiq.options[:average_scheduled_poll_interval] = 10
|
97
|
+
```
|
98
|
+
|
99
|
+
The default value at time of writing is 30 seconds. See [under the hood](#under-the-hood) for more details.
|
72
100
|
|
73
101
|
### What objects/classes can be scheduled
|
102
|
+
|
74
103
|
#### Sidekiq Worker
|
104
|
+
|
75
105
|
In this example, we are using `HardWorker` which looks like:
|
106
|
+
|
76
107
|
```ruby
|
77
108
|
class HardWorker
|
78
109
|
include Sidekiq::Worker
|
110
|
+
|
79
111
|
def perform(*args)
|
80
112
|
# do something
|
81
113
|
end
|
@@ -83,7 +115,9 @@ end
|
|
83
115
|
```
|
84
116
|
|
85
117
|
#### Active Job Worker
|
86
|
-
|
118
|
+
|
119
|
+
You can schedule `ExampleJob` which looks like:
|
120
|
+
|
87
121
|
```ruby
|
88
122
|
class ExampleJob < ActiveJob::Base
|
89
123
|
queue_as :default
|
@@ -94,11 +128,15 @@ class ExampleJob < ActiveJob::Base
|
|
94
128
|
end
|
95
129
|
```
|
96
130
|
|
97
|
-
|
98
|
-
|
131
|
+
For Active jobs you can use `symbolize_args: true` in `Sidekiq::Cron::Job.create` or in Hash configuration,
|
132
|
+
which will ensure that arguments you are passing to it will be symbolized when passed back to `perform` method in worker.
|
133
|
+
|
134
|
+
#### Adding Cron job
|
99
135
|
|
136
|
+
```ruby
|
100
137
|
class HardWorker
|
101
138
|
include Sidekiq::Worker
|
139
|
+
|
102
140
|
def perform(name, count)
|
103
141
|
# do something
|
104
142
|
end
|
@@ -119,16 +157,15 @@ else
|
|
119
157
|
puts job.errors
|
120
158
|
end
|
121
159
|
|
122
|
-
#or simple
|
123
|
-
|
160
|
+
# or simple
|
124
161
|
unless job.save
|
125
|
-
puts job.errors #will return array of errors
|
162
|
+
puts job.errors # will return array of errors
|
126
163
|
end
|
127
164
|
```
|
128
165
|
|
129
166
|
Load more jobs from hash:
|
130
|
-
```ruby
|
131
167
|
|
168
|
+
```ruby
|
132
169
|
hash = {
|
133
170
|
'name_of_job' => {
|
134
171
|
'class' => 'MyClass',
|
@@ -145,6 +182,7 @@ Sidekiq::Cron::Job.load_from_hash hash
|
|
145
182
|
```
|
146
183
|
|
147
184
|
Load more jobs from array:
|
185
|
+
|
148
186
|
```ruby
|
149
187
|
array = [
|
150
188
|
{
|
@@ -163,17 +201,17 @@ array = [
|
|
163
201
|
Sidekiq::Cron::Job.load_from_array array
|
164
202
|
```
|
165
203
|
|
166
|
-
Bang-suffixed methods will remove jobs that are not present in the given hash/array,
|
167
|
-
update jobs that have the same names, and create new ones when the names are previously unknown.
|
204
|
+
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.
|
168
205
|
|
169
206
|
```ruby
|
170
|
-
Sidekiq::Cron::Job
|
171
|
-
Sidekiq::Cron::Job
|
207
|
+
Sidekiq::Cron::Job.load_from_hash! hash
|
208
|
+
Sidekiq::Cron::Job.load_from_array! array
|
172
209
|
```
|
173
210
|
|
174
|
-
|
211
|
+
Or from YAML (same notation as Resque-scheduler):
|
212
|
+
|
175
213
|
```yaml
|
176
|
-
#config/schedule.yml
|
214
|
+
# config/schedule.yml
|
177
215
|
|
178
216
|
my_first_job:
|
179
217
|
cron: "*/5 * * * *"
|
@@ -189,64 +227,84 @@ second_job:
|
|
189
227
|
```
|
190
228
|
|
191
229
|
```ruby
|
192
|
-
#initializers/sidekiq.rb
|
230
|
+
# config/initializers/sidekiq.rb
|
193
231
|
schedule_file = "config/schedule.yml"
|
194
232
|
|
195
|
-
if File.
|
233
|
+
if File.exist?(schedule_file) && Sidekiq.server?
|
196
234
|
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
197
235
|
end
|
198
236
|
```
|
199
237
|
|
200
|
-
|
238
|
+
From version 3.x it is better not to use separate initializer of schedule instead add `config.on(:startup)` to your Sidekiq configuration:
|
201
239
|
|
202
|
-
#### Finding jobs
|
203
240
|
```ruby
|
204
|
-
|
241
|
+
Sidekiq.configure_server do |config|
|
242
|
+
config.on(:startup) do
|
243
|
+
schedule_file = "config/schedule.yml"
|
244
|
+
|
245
|
+
if File.exist?(schedule_file)
|
246
|
+
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
```
|
251
|
+
|
252
|
+
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.
|
253
|
+
|
254
|
+
### Finding jobs
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
# return array of all jobs
|
205
258
|
Sidekiq::Cron::Job.all
|
206
259
|
|
207
|
-
#return one job by its unique name - case sensitive
|
260
|
+
# return one job by its unique name - case sensitive
|
208
261
|
Sidekiq::Cron::Job.find "Job Name"
|
209
262
|
|
210
|
-
#return one job by its unique name - you can use hash with 'name' key
|
263
|
+
# return one job by its unique name - you can use hash with 'name' key
|
211
264
|
Sidekiq::Cron::Job.find name: "Job Name"
|
212
265
|
|
213
|
-
#if job can't be found nil is returned
|
266
|
+
# if job can't be found nil is returned
|
214
267
|
```
|
215
268
|
|
216
|
-
|
269
|
+
### Destroy jobs
|
270
|
+
|
217
271
|
```ruby
|
218
|
-
#
|
272
|
+
# destroy all jobs
|
219
273
|
Sidekiq::Cron::Job.destroy_all!
|
220
274
|
|
221
|
-
#destroy job by its name
|
275
|
+
# destroy job by its name
|
222
276
|
Sidekiq::Cron::Job.destroy "Job Name"
|
223
277
|
|
224
|
-
#destroy found job
|
278
|
+
# destroy found job
|
225
279
|
Sidekiq::Cron::Job.find('Job name').destroy
|
226
280
|
```
|
227
281
|
|
228
|
-
|
282
|
+
### Work with job
|
283
|
+
|
229
284
|
```ruby
|
230
285
|
job = Sidekiq::Cron::Job.find('Job name')
|
231
286
|
|
232
|
-
#disable cron scheduling
|
287
|
+
# disable cron scheduling
|
233
288
|
job.disable!
|
234
289
|
|
235
|
-
#enable cron scheduling
|
290
|
+
# enable cron scheduling
|
236
291
|
job.enable!
|
237
292
|
|
238
|
-
#get status of job:
|
293
|
+
# get status of job:
|
239
294
|
job.status
|
240
295
|
# => enabled/disabled
|
241
296
|
|
242
|
-
#enqueue job right now!
|
297
|
+
# enqueue job right now!
|
243
298
|
job.enque!
|
244
299
|
```
|
245
300
|
|
246
|
-
How to start scheduling?
|
301
|
+
### How to start scheduling?
|
302
|
+
|
247
303
|
Just start Sidekiq workers by running:
|
248
304
|
|
249
|
-
|
305
|
+
```
|
306
|
+
$ sidekiq
|
307
|
+
```
|
250
308
|
|
251
309
|
### Web UI for Cron Jobs
|
252
310
|
|
@@ -254,66 +312,67 @@ If you are using Sidekiq's web UI and you would like to add cron jobs too to thi
|
|
254
312
|
add `require 'sidekiq/cron/web'` after `require 'sidekiq/web'`.
|
255
313
|
|
256
314
|
With this, you will get:
|
257
|
-

|
258
315
|
|
259
|
-
|
316
|
+

|
317
|
+
|
318
|
+
### Forking Processes or problem with `NotImplementedError`
|
260
319
|
|
261
320
|
If you're using a forking web server like Unicorn you may run into an issue where the Redis connection is used
|
262
|
-
before the process forks, causing the following exception
|
321
|
+
before the process forks, causing the following exception to occur:
|
263
322
|
|
264
|
-
|
323
|
+
```
|
324
|
+
Redis::InheritedError: Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.
|
325
|
+
```
|
265
326
|
|
266
|
-
|
327
|
+
To avoid this, wrap your job creation in the call to `Sidekiq.configure_server`:
|
267
328
|
|
268
329
|
```ruby
|
269
330
|
Sidekiq.configure_server do |config|
|
270
|
-
|
331
|
+
config.on(:startup) do
|
332
|
+
schedule_file = "config/schedule.yml"
|
271
333
|
|
272
|
-
|
273
|
-
|
334
|
+
if File.exist?(schedule_file)
|
335
|
+
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
336
|
+
end
|
274
337
|
end
|
275
338
|
end
|
276
339
|
```
|
277
340
|
|
278
|
-
|
341
|
+
**NOTE** This API is only available in Sidekiq 3.x.
|
279
342
|
|
280
343
|
## Under the hood
|
281
344
|
|
282
345
|
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.
|
283
346
|
|
284
|
-
Sidekiq-Cron adds itself into this start procedure and starts another thread with `Sidekiq::Cron::Poller` which checks all enabled Sidekiq cron jobs every
|
347
|
+
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).
|
285
348
|
|
286
349
|
Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can change it by setting:
|
287
|
-
|
288
|
-
|
350
|
+
|
351
|
+
```ruby
|
352
|
+
Sidekiq.options[:average_scheduled_poll_interval] = 10
|
289
353
|
```
|
290
354
|
|
291
|
-
|
292
|
-
* [@7korobi](https://github.com/7korobi)
|
293
|
-
* [@antulik](https://github.com/antulik)
|
294
|
-
* [@felixbuenemann](https://github.com/felixbuenemann)
|
295
|
-
* [@gstark](https://github.com/gstark)
|
296
|
-
* [@RajRoR](https://github.com/RajRoR)
|
297
|
-
* [@romeuhcf](https://github.com/romeuhcf)
|
298
|
-
* [@siruguri](https://github.com/siruguri)
|
299
|
-
* [@Soliah](https://github.com/Soliah)
|
300
|
-
* [@stephankaag](https://github.com/stephankaag)
|
301
|
-
* [@sue445](https://github.com/sue445)
|
302
|
-
* [@sylg](https://github.com/sylg)
|
303
|
-
* [@tmeinlschmidt](https://github.com/tmeinlschmidt)
|
304
|
-
* [@zerobearing2](https://github.com/zerobearing2)
|
355
|
+
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.
|
305
356
|
|
357
|
+
## Contributing
|
306
358
|
|
307
|
-
|
359
|
+
**Thanks to all [contributors](https://github.com/ondrejbartas/sidekiq-cron/graphs/contributors), you’re awesome and this wouldn’t be possible without you!**
|
308
360
|
|
309
361
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
310
362
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
311
363
|
* Fork the project.
|
312
364
|
* Start a feature/bugfix branch.
|
313
365
|
* Commit and push until you are happy with your contribution.
|
314
|
-
* Make sure to add tests for it. This is important so
|
315
|
-
|
366
|
+
* Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
|
367
|
+
|
368
|
+
### Testing
|
369
|
+
|
370
|
+
You can execute the test suite by running:
|
371
|
+
|
372
|
+
```
|
373
|
+
$ bundle exec rake test
|
374
|
+
```
|
316
375
|
|
317
|
-
##
|
376
|
+
## License
|
318
377
|
|
319
|
-
Copyright (c) 2013 Ondrej Bartas. See LICENSE.txt for further details.
|
378
|
+
Copyright (c) 2013 Ondrej Bartas. See [LICENSE](LICENSE.txt) for further details.
|