sidekiq-cron 1.5.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +161 -0
- data/Gemfile +3 -0
- data/README.md +74 -66
- data/lib/sidekiq/cron/job.rb +191 -132
- data/lib/sidekiq/cron/launcher.rb +17 -15
- data/lib/sidekiq/cron/locales/it.yml +23 -0
- data/lib/sidekiq/cron/poller.rb +14 -18
- data/lib/sidekiq/cron/schedule_loader.rb +20 -0
- data/lib/sidekiq/cron/support.rb +8 -1
- data/lib/sidekiq/cron/version.rb +1 -1
- data/lib/sidekiq/cron/views/cron.erb +1 -1
- data/lib/sidekiq/cron/web_extension.rb +6 -9
- data/lib/sidekiq/cron.rb +1 -0
- data/lib/sidekiq/options.rb +29 -0
- data/sidekiq-cron.gemspec +12 -13
- metadata +45 -32
- data/Changes.md +0 -111
- data/test/integration/performance_test.rb +0 -49
- data/test/test_helper.rb +0 -92
- data/test/unit/job_test.rb +0 -1124
- data/test/unit/poller_test.rb +0 -150
- data/test/unit/web_extension_test.rb +0 -156
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaa6af217265c4e60b29018b984b43a4316b2618e52ce874db670e41ecadf85b
|
4
|
+
data.tar.gz: f70a50a90508ceb32bad90b8b2b6a880fb460f308dfa81f7380152742bb939cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef95b33d15c1867a3dc6cc096080af6f2fab50c4460d8be24948bcd887c6c278dc3ca1a8c92db8d1ce386d24e0ceb95f53f6add336c3315fec04f808b7451475
|
7
|
+
data.tar.gz: e30e02e3bcc13f8604426d5d9e5f30e24c46a85bfd7679544975a3bdfcc0510631d363ef041f948c8a51e289a02a222fd27bba572cf57ac1697aabb917673a01
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
## 1.12.0
|
6
|
+
|
7
|
+
- Remove Sidekiq.server? check from schedule loader (https://github.com/sidekiq-cron/sidekiq-cron/pull/436)
|
8
|
+
- Parse arguments on `args=` method (https://github.com/sidekiq-cron/sidekiq-cron/pull/442)
|
9
|
+
- Only check out a Redis connection if necessary (https://github.com/sidekiq-cron/sidekiq-cron/pull/438)
|
10
|
+
|
11
|
+
## 1.11.0
|
12
|
+
|
13
|
+
- Differentiates b/w "schedule" vs "dynamic" jobs (https://github.com/sidekiq-cron/sidekiq-cron/pull/431)
|
14
|
+
- Clears scheduled jobs upon schedule load (https://github.com/sidekiq-cron/sidekiq-cron/pull/431)
|
15
|
+
- Reduce gem size by excluding test files (https://github.com/sidekiq-cron/sidekiq-cron/pull/414)
|
16
|
+
|
17
|
+
## 1.10.1
|
18
|
+
|
19
|
+
- Use `hset` instead of deprecated `hmset` (https://github.com/sidekiq-cron/sidekiq-cron/pull/410)
|
20
|
+
|
21
|
+
## 1.10.0
|
22
|
+
|
23
|
+
- Remove EOL Ruby 2.6 support (https://github.com/sidekiq-cron/sidekiq-cron/pull/399)
|
24
|
+
- Add a logo for the project! (https://github.com/sidekiq-cron/sidekiq-cron/pull/402)
|
25
|
+
- Added support for ActiveRecord serialize/deserialize using GlobalID (https://github.com/sidekiq-cron/sidekiq-cron/pull/395)
|
26
|
+
- Allow for keyword args (`embedded: true`) in Poller (https://github.com/sidekiq-cron/sidekiq-cron/pull/398)
|
27
|
+
- Make last_enqueue_time be always an instance of Time (https://github.com/sidekiq-cron/sidekiq-cron/pull/354)
|
28
|
+
- Fix argument error problem update from 1.6.0 to newer (https://github.com/sidekiq-cron/sidekiq-cron/pull/392)
|
29
|
+
- Clear old jobs while loading the jobs from schedule via the schedule loader (https://github.com/sidekiq-cron/sidekiq-cron/pull/405)
|
30
|
+
|
31
|
+
## 1.9.1
|
32
|
+
|
33
|
+
- Always enqueue via Active Job interface when defined in cron job config (https://github.com/sidekiq-cron/sidekiq-cron/pull/381)
|
34
|
+
- Fix schedule.yml YAML load errors on Ruby 3.1 (https://github.com/sidekiq-cron/sidekiq-cron/pull/386)
|
35
|
+
- Require Fugit v1.8 to refactor internals (https://github.com/sidekiq-cron/sidekiq-cron/pull/385)
|
36
|
+
|
37
|
+
## 1.9.0
|
38
|
+
|
39
|
+
- Sidekiq v7 support (https://github.com/sidekiq-cron/sidekiq-cron/pull/369)
|
40
|
+
- Add support for ERB templates in the auto schedule loader (https://github.com/sidekiq-cron/sidekiq-cron/pull/373)
|
41
|
+
|
42
|
+
## 1.8.0
|
43
|
+
|
44
|
+
- Fix deprecation warnings with redis-rb v4.8.0 (https://github.com/sidekiq-cron/sidekiq-cron/pull/356)
|
45
|
+
- Fix poller affecting Sidekiq scheduled set poller (https://github.com/sidekiq-cron/sidekiq-cron/pull/359)
|
46
|
+
- Fix default polling interval (https://github.com/sidekiq-cron/sidekiq-cron/pull/362)
|
47
|
+
- Add italian locale (https://github.com/sidekiq-cron/sidekiq-cron/pull/367)
|
48
|
+
- Allow disabling of cron polling (https://github.com/sidekiq-cron/sidekiq-cron/pull/368)
|
49
|
+
|
50
|
+
## 1.7.0
|
51
|
+
|
52
|
+
- Enable to use cron notation in natural language (ie `every 30 minutes`) (https://github.com/sidekiq-cron/sidekiq-cron/pull/312)
|
53
|
+
- Fix `date_as_argument` feature to add timestamp argument at every cron job execution (https://github.com/sidekiq-cron/sidekiq-cron/pull/329)
|
54
|
+
- Introduce `Sidekiq::Options` to centralize reading/writing options from different Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/341)
|
55
|
+
- Make auto schedule loading compatible with Array format (https://github.com/sidekiq-cron/sidekiq-cron/pull/345)
|
56
|
+
|
57
|
+
## 1.6.0
|
58
|
+
|
59
|
+
- Adds support for auto-loading the `config/schedule.yml` file (https://github.com/sidekiq-cron/sidekiq-cron/pull/337)
|
60
|
+
- Fix `Sidekiq.options` deprecation warning (https://github.com/sidekiq-cron/sidekiq-cron/pull/338)
|
61
|
+
|
62
|
+
## 1.5.1
|
63
|
+
|
64
|
+
- Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/sidekiq-cron/sidekiq-cron/pull/335)
|
65
|
+
|
66
|
+
## 1.5.0
|
67
|
+
|
68
|
+
- Integrate Sidekiq v6.5 breaking changes (https://github.com/sidekiq-cron/sidekiq-cron/pull/331)
|
69
|
+
- Add portuguese translations (https://github.com/sidekiq-cron/sidekiq-cron/pull/332)
|
70
|
+
|
71
|
+
## 1.4.0
|
72
|
+
|
73
|
+
- Fix buttons order in job show view (https://github.com/sidekiq-cron/sidekiq-cron/pull/302)
|
74
|
+
- Dark Mode support in UI (https://github.com/sidekiq-cron/sidekiq-cron/pull/282)
|
75
|
+
- Remove invocation of deprecated Redis functionality (https://github.com/sidekiq-cron/sidekiq-cron/pull/318)
|
76
|
+
- Internal code cleanup (https://github.com/sidekiq-cron/sidekiq-cron/pull/317)
|
77
|
+
- Optimize gem size (https://github.com/sidekiq-cron/sidekiq-cron/pull/322)
|
78
|
+
- Fix "Show All" button on cron jobs view with Sidekiq 6.3.0+ (https://github.com/sidekiq-cron/sidekiq-cron/pull/321)
|
79
|
+
- Documentation updates
|
80
|
+
|
81
|
+
## 1.3.0
|
82
|
+
|
83
|
+
- Add confirmation dialog when enquing jobs from UI
|
84
|
+
- Start to support Sidekiq `average_scheduled_poll_interval` option (replaced `poll_interval`)
|
85
|
+
- Fix deprecation warning for Redis 4.6.x
|
86
|
+
- Fix different response from Redis#exists in different Redis versions
|
87
|
+
- All PRs:
|
88
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/275
|
89
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/287
|
90
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/309
|
91
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/299
|
92
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/314
|
93
|
+
- https://github.com/sidekiq-cron/sidekiq-cron/pull/288
|
94
|
+
|
95
|
+
## 1.2.0
|
96
|
+
|
97
|
+
- Updated readme
|
98
|
+
- Fix problem with Sidekiq::Launcher and requiring it when not needed
|
99
|
+
- Better patching of Sidekiq::Launcher
|
100
|
+
- Fixed Dockerfile
|
101
|
+
|
102
|
+
## 1.1.0
|
103
|
+
|
104
|
+
- Updated readme
|
105
|
+
- Fix unit tests - changed argument error when getting invalid cron format
|
106
|
+
- When fallbacking old job enqueued time use `Time.parse` without format (so Ruby can decide best method to parse it)
|
107
|
+
- Add option `date_as_argument` which will add to your job arguments on last place `Time.now.to_f` when it was eneuqued
|
108
|
+
- Add option `description` which will allow you to add notes to your jobs so in web view you can see it
|
109
|
+
- Fixed translations
|
110
|
+
|
111
|
+
## 1.0.4
|
112
|
+
|
113
|
+
- Fix problem with upgrading to 1.0.x - parsing last enqued time didn't count with old time format stored in Redis
|
114
|
+
|
115
|
+
## 1.0.0
|
116
|
+
|
117
|
+
- 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)
|
118
|
+
- Better working with Timezones
|
119
|
+
- Translations for JA, zh-CN
|
120
|
+
- Cron without timezone are considered as UTC, to add Timezone to cron use format `* * * * * Europe/Berlin`
|
121
|
+
- 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)
|
122
|
+
|
123
|
+
## 0.6.0
|
124
|
+
|
125
|
+
- Set poller to check jobs every 30s by default (possible to override by `Sidekiq.options[:poll_interval] = 10`)
|
126
|
+
- Add group actions (enqueue, enable, disable, delete) all in web view
|
127
|
+
- Fix poller to enqueu all jobs in poll start time
|
128
|
+
- Add performance test for enqueue of jobs (10 000 jobs in less than 19s)
|
129
|
+
- Fix problem with default queue
|
130
|
+
- Remove `redis-namespace` from dependencies
|
131
|
+
- Update Ruby versions in Travis
|
132
|
+
|
133
|
+
## 0.5.0
|
134
|
+
|
135
|
+
- Add Docker support
|
136
|
+
- All crons are now evaluated in UTC
|
137
|
+
- Fix rufus scheduler & timezones problems
|
138
|
+
- Add support for Sidekiq 4.2.1
|
139
|
+
- Fix readme
|
140
|
+
- Add Russian locale
|
141
|
+
- User Rack.env in tests
|
142
|
+
- Faster enqueue of jobs
|
143
|
+
- Permit to use `ActiveJob::Base.queue_name_delimiter`
|
144
|
+
- Fix problem with multiple times enqueue #84
|
145
|
+
- Fix problem with enqueue of unknown class
|
146
|
+
|
147
|
+
## 0.4.0
|
148
|
+
|
149
|
+
- Enable to work with Sidekiq >= 4.0.0
|
150
|
+
- Fix readme
|
151
|
+
|
152
|
+
## 0.3.1
|
153
|
+
|
154
|
+
- Add CSRF tags to forms so it will work with Sidekiq >= 3.4.2
|
155
|
+
- Remove Tilt dependency
|
156
|
+
|
157
|
+
## 0.3.0
|
158
|
+
|
159
|
+
- Suport for Active Job
|
160
|
+
- Sidekiq cron web ui needs to be loaded by: require 'sidekiq/cron/web'
|
161
|
+
- Add load_from_hash! and load_from_array! which cleanup jobs before adding new ones
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
1
|
+
![Sidekiq-Cron](logos/cover.png)
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/sidekiq-cron.svg)](https://badge.fury.io/rb/sidekiq-cron)
|
4
|
-
[![Build Status](https://github.com/
|
5
|
-
[![
|
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)
|
4
|
+
[![Build Status](https://github.com/sidekiq-cron/sidekiq-cron/workflows/CI/badge.svg?branch=master)](https://github.com/sidekiq-cron/sidekiq-cron/actions)
|
5
|
+
[![codecov](https://codecov.io/gh/sidekiq-cron/sidekiq-cron/branch/master/graph/badge.svg?token=VK9IVLIaY8)](https://codecov.io/gh/sidekiq-cron/sidekiq-cron)
|
7
6
|
|
8
7
|
> A scheduling add-on for [Sidekiq](https://sidekiq.org/)
|
9
8
|
|
@@ -21,22 +20,12 @@ Works with ActiveJob (Rails 4.2+).
|
|
21
20
|
|
22
21
|
You don't need Sidekiq PRO, you can use this gem with plain Sidekiq.
|
23
22
|
|
24
|
-
## Upgrade from < 0.6 to 1.0
|
25
|
-
|
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
|
-
|
28
23
|
## Changelog
|
29
24
|
|
30
|
-
Before upgrading to a new version, please read our [Changelog](
|
25
|
+
Before upgrading to a new version, please read our [Changelog](CHANGELOG.md).
|
31
26
|
|
32
27
|
## Installation
|
33
28
|
|
34
|
-
### Requirements
|
35
|
-
|
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)
|
38
|
-
- Sidekiq 6.5 requires Sidekiq-Cron 1.5+
|
39
|
-
|
40
29
|
Install the gem:
|
41
30
|
|
42
31
|
```
|
@@ -53,21 +42,23 @@ gem "sidekiq-cron"
|
|
53
42
|
|
54
43
|
## Getting Started
|
55
44
|
|
56
|
-
|
45
|
+
### Job properties
|
57
46
|
|
58
47
|
```ruby
|
59
48
|
{
|
49
|
+
# MANDATORY
|
60
50
|
'name' => 'name_of_job', # must be uniq!
|
61
|
-
'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01,
|
51
|
+
'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01, ...
|
62
52
|
'class' => 'MyClass',
|
63
53
|
# OPTIONAL
|
54
|
+
'source' => 'dynamic', # source of the job, `schedule`/`dynamic` (default: `dynamic`)
|
64
55
|
'queue' => 'name of queue',
|
65
56
|
'args' => '[Array or Hash] of arguments which will be passed to perform method',
|
66
57
|
'date_as_argument' => true, # add the time of execution as last argument of the perform method
|
67
|
-
'active_job' => true, # enqueue job through
|
68
|
-
'queue_name_prefix' => 'prefix', #
|
69
|
-
'queue_name_delimiter' => '.',
|
70
|
-
'description' => 'A sentence describing what work this job performs
|
58
|
+
'active_job' => true, # enqueue job through Rails 4.2+ Active Job interface
|
59
|
+
'queue_name_prefix' => 'prefix', # Rails 4.2+ Active Job queue with prefix
|
60
|
+
'queue_name_delimiter' => '.', # Rails 4.2+ Active Job queue with custom delimiter (default: '_')
|
61
|
+
'description' => 'A sentence describing what work this job performs'
|
71
62
|
'status' => 'disabled' # default: enabled
|
72
63
|
}
|
73
64
|
```
|
@@ -83,6 +74,17 @@ If using Rails, this is evaluated against the timezone configured in Rails, othe
|
|
83
74
|
If you want to have your jobs enqueued based on a different time zone you can specify a timezone in the cronline,
|
84
75
|
like this `'0 22 * * 1-5 America/Chicago'`.
|
85
76
|
|
77
|
+
#### Natural-language formats
|
78
|
+
|
79
|
+
Since sidekiq-cron `v1.7.0`, you can use the natural-language formats supported by Fugit, such as:
|
80
|
+
|
81
|
+
```rb
|
82
|
+
"every day at five" # => '0 5 * * *'
|
83
|
+
"every 3 hours" # => '0 */3 * * *'
|
84
|
+
```
|
85
|
+
|
86
|
+
See [the relevant part of Fugit documentation](https://github.com/floraison/fugit#fugitnat) for details.
|
87
|
+
|
86
88
|
#### Second-precision (sub-minute) cronlines
|
87
89
|
|
88
90
|
In addition to the standard 5-parameter cronline format, sidekiq-cron supports scheduling jobs with second-precision using a modified 6-parameter cronline format:
|
@@ -94,7 +96,7 @@ For example: `"*/30 * * * * *"` would schedule a job to run every 30 seconds.
|
|
94
96
|
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:
|
95
97
|
|
96
98
|
```ruby
|
97
|
-
Sidekiq
|
99
|
+
Sidekiq::Options[:cron_poll_interval] = 10
|
98
100
|
```
|
99
101
|
|
100
102
|
The default value at time of writing is 30 seconds. See [under the hood](#under-the-hood) for more details.
|
@@ -134,6 +136,8 @@ which will ensure that arguments you are passing to it will be symbolized when p
|
|
134
136
|
|
135
137
|
#### Adding Cron job
|
136
138
|
|
139
|
+
Refer to [Schedule vs Dynamic jobs](#schedule-vs-dynamic-jobs) to understand the difference.
|
140
|
+
|
137
141
|
```ruby
|
138
142
|
class HardWorker
|
139
143
|
include Sidekiq::Worker
|
@@ -143,7 +147,7 @@ class HardWorker
|
|
143
147
|
end
|
144
148
|
end
|
145
149
|
|
146
|
-
Sidekiq::Cron::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker') # execute at every 5 minutes
|
150
|
+
Sidekiq::Cron::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker') # execute at every 5 minutes
|
147
151
|
# => true
|
148
152
|
```
|
149
153
|
|
@@ -164,6 +168,26 @@ unless job.save
|
|
164
168
|
end
|
165
169
|
```
|
166
170
|
|
171
|
+
Use ActiveRecord models as arguments
|
172
|
+
|
173
|
+
```rb
|
174
|
+
class Person < ApplicationRecord
|
175
|
+
end
|
176
|
+
|
177
|
+
class HardWorker < ActiveJob::Base
|
178
|
+
queue_as :default
|
179
|
+
|
180
|
+
def perform(person)
|
181
|
+
puts "person: #{person}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
person = Person.create(id: 1)
|
187
|
+
Sidekiq::Cron::Job.create(name: 'Hard worker - every 5min', cron: '*/5 * * * *', class: 'HardWorker', args: person)
|
188
|
+
# => true
|
189
|
+
```
|
190
|
+
|
167
191
|
Load more jobs from hash:
|
168
192
|
|
169
193
|
```ruby
|
@@ -202,7 +226,7 @@ array = [
|
|
202
226
|
Sidekiq::Cron::Job.load_from_array array
|
203
227
|
```
|
204
228
|
|
205
|
-
Bang-suffixed methods will remove jobs
|
229
|
+
Bang-suffixed methods will remove jobs where source is `schedule` and 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.
|
206
230
|
|
207
231
|
```ruby
|
208
232
|
Sidekiq::Cron::Job.load_from_hash! hash
|
@@ -227,31 +251,28 @@ second_job:
|
|
227
251
|
hard: "stuff"
|
228
252
|
```
|
229
253
|
|
230
|
-
|
231
|
-
# config/initializers/sidekiq.rb
|
232
|
-
schedule_file = "config/schedule.yml"
|
233
|
-
|
234
|
-
if File.exist?(schedule_file) && Sidekiq.server?
|
235
|
-
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
236
|
-
end
|
237
|
-
```
|
254
|
+
There are multiple ways to load the jobs from a YAML file
|
238
255
|
|
239
|
-
|
256
|
+
1. The gem will automatically load the jobs mentioned in `config/schedule.yml` file (it supports ERB)
|
257
|
+
2. When you want to load jobs from a different filename, mention the filename in sidekiq configuration, i.e. `cron_schedule_file: "config/users_schedule.yml"`
|
258
|
+
3. Load the file manually as follows:
|
240
259
|
|
241
260
|
```ruby
|
261
|
+
# config/initializers/sidekiq.rb
|
262
|
+
|
242
263
|
Sidekiq.configure_server do |config|
|
243
264
|
config.on(:startup) do
|
244
|
-
schedule_file = "config/
|
265
|
+
schedule_file = "config/users_schedule.yml"
|
245
266
|
|
246
267
|
if File.exist?(schedule_file)
|
247
|
-
|
268
|
+
schedule = YAML.load_file(schedule_file)
|
269
|
+
|
270
|
+
Sidekiq::Cron::Job.load_from_hash!(schedule, source: "schedule")
|
248
271
|
end
|
249
272
|
end
|
250
273
|
end
|
251
274
|
```
|
252
275
|
|
253
|
-
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.
|
254
|
-
|
255
276
|
### Finding jobs
|
256
277
|
|
257
278
|
```ruby
|
@@ -299,12 +320,22 @@ job.status
|
|
299
320
|
job.enque!
|
300
321
|
```
|
301
322
|
|
323
|
+
### Schedule vs Dynamic jobs
|
324
|
+
|
325
|
+
There are two potential job sources: `schedule` and `dynamic`.
|
326
|
+
Jobs associated with schedule files are labeled as `schedule` as their source,
|
327
|
+
whereas jobs created at runtime without the `source=schedule` argument are classified as `dynamic`.
|
328
|
+
|
329
|
+
The key distinction lies in how these jobs are managed.
|
330
|
+
When a schedule is loaded, any stale `schedule` jobs are automatically removed to ensure synchronization within the schedule.
|
331
|
+
The `dynamic` jobs remain unaffected by this process.
|
332
|
+
|
302
333
|
### How to start scheduling?
|
303
334
|
|
304
335
|
Just start Sidekiq workers by running:
|
305
336
|
|
306
337
|
```
|
307
|
-
$ sidekiq
|
338
|
+
$ bundle exec sidekiq
|
308
339
|
```
|
309
340
|
|
310
341
|
### Web UI for Cron Jobs
|
@@ -314,32 +345,7 @@ add `require 'sidekiq/cron/web'` after `require 'sidekiq/web'`.
|
|
314
345
|
|
315
346
|
With this, you will get:
|
316
347
|
|
317
|
-
![Web UI](
|
318
|
-
|
319
|
-
### Forking Processes or problem with `NotImplementedError`
|
320
|
-
|
321
|
-
If you're using a forking web server like Unicorn you may run into an issue where the Redis connection is used
|
322
|
-
before the process forks, causing the following exception to occur:
|
323
|
-
|
324
|
-
```
|
325
|
-
Redis::InheritedError: Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.
|
326
|
-
```
|
327
|
-
|
328
|
-
To avoid this, wrap your job creation in the call to `Sidekiq.configure_server`:
|
329
|
-
|
330
|
-
```ruby
|
331
|
-
Sidekiq.configure_server do |config|
|
332
|
-
config.on(:startup) do
|
333
|
-
schedule_file = "config/schedule.yml"
|
334
|
-
|
335
|
-
if File.exist?(schedule_file)
|
336
|
-
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
```
|
341
|
-
|
342
|
-
**NOTE** This API is only available in Sidekiq 3.x.
|
348
|
+
![Web UI](docs/images/web-cron-ui.jpeg)
|
343
349
|
|
344
350
|
## Under the hood
|
345
351
|
|
@@ -350,14 +356,16 @@ Sidekiq-Cron adds itself into this start procedure and starts another thread wit
|
|
350
356
|
Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can change it by setting:
|
351
357
|
|
352
358
|
```ruby
|
353
|
-
Sidekiq
|
359
|
+
Sidekiq::Options[:cron_poll_interval] = 10
|
354
360
|
```
|
355
361
|
|
356
362
|
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.
|
357
363
|
|
364
|
+
When running with many Sidekiq processes, the polling can add significant load to Redis. You can disable polling on some processes by setting `Sidekiq::Options[:cron_poll_interval] = 0` on these processes.
|
365
|
+
|
358
366
|
## Contributing
|
359
367
|
|
360
|
-
**Thanks to all [contributors](https://github.com/
|
368
|
+
**Thanks to all [contributors](https://github.com/sidekiq-cron/sidekiq-cron/graphs/contributors), you’re awesome and this wouldn’t be possible without you!**
|
361
369
|
|
362
370
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
363
371
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|