sidekiq-cron 1.2.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d16f511a8148eadb1246263f53b596b643f9a653e0fb7877e8eaa6e0d0f2f57c
|
4
|
+
data.tar.gz: 874babda0f4da8f7928b69a226b967d79d59eacc79c101d0e087f064d31e6423
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23cfaf18069f8e85b777807e2ceaab25d7a0d58983541044e84791e5f484998d00b5042f1f25222f050f7900d182c371227c03270cd66243c440d02cf98065b
|
7
|
+
data.tar.gz: 4e809ad13f7cde7f02a3e3ea44c6500e3e430c95e8ae12136b7625bc8ab7a452748e3769adbbef619d033a4346800693b329c40c1f4836594e8c242e4089737f
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
## 1.7.0
|
6
|
+
|
7
|
+
- Enable to use cron notation in natural language (ie `every 30 minutes`) (https://github.com/ondrejbartas/sidekiq-cron/pull/312)
|
8
|
+
- Fix `date_as_argument` feature to add timestamp argument at every cron job execution (https://github.com/ondrejbartas/sidekiq-cron/pull/329)
|
9
|
+
- Introduce `Sidekiq::Options` to centralize reading/writing options from different Sidekiq versions (https://github.com/ondrejbartas/sidekiq-cron/pull/341)
|
10
|
+
- Make auto schedule loading compatible with Array format (https://github.com/ondrejbartas/sidekiq-cron/pull/345)
|
11
|
+
|
12
|
+
## 1.6.0
|
13
|
+
|
14
|
+
- Adds support for auto-loading the `config/schedule.yml` file (https://github.com/ondrejbartas/sidekiq-cron/pull/337)
|
15
|
+
- Fix `Sidekiq.options` deprecation warning (https://github.com/ondrejbartas/sidekiq-cron/pull/338)
|
16
|
+
|
17
|
+
## 1.5.1
|
18
|
+
|
19
|
+
- Fixes an issue that prevented the gem to work in previous Sidekiq versions (https://github.com/ondrejbartas/sidekiq-cron/pull/335)
|
20
|
+
|
21
|
+
## 1.5.0
|
22
|
+
|
23
|
+
- Integrate Sidekiq v6.5 breaking changes (https://github.com/ondrejbartas/sidekiq-cron/pull/331)
|
24
|
+
- Add portuguese translations (https://github.com/ondrejbartas/sidekiq-cron/pull/332)
|
25
|
+
|
26
|
+
## 1.4.0
|
27
|
+
|
28
|
+
- Fix buttons order in job show view (https://github.com/ondrejbartas/sidekiq-cron/pull/302)
|
29
|
+
- Dark Mode support in UI (https://github.com/ondrejbartas/sidekiq-cron/pull/317/282)
|
30
|
+
- Remove invocation of deprecated Redis functionality (https://github.com/ondrejbartas/sidekiq-cron/pull/318)
|
31
|
+
- Internal code cleanup (https://github.com/ondrejbartas/sidekiq-cron/pull/317)
|
32
|
+
- Optimize gem size (https://github.com/ondrejbartas/sidekiq-cron/pull/322)
|
33
|
+
- Fix "Show All" button on cron jobs view with Sidekiq 6.3.0+ (https://github.com/ondrejbartas/sidekiq-cron/pull/321)
|
34
|
+
- Documentation updates
|
35
|
+
|
36
|
+
## 1.3.0
|
37
|
+
|
38
|
+
- Add confirmation dialog when enquing jobs from UI
|
39
|
+
- Start to support Sidekiq `average_scheduled_poll_interval` option (replaced `poll_interval`)
|
40
|
+
- Fix deprecation warning for Redis 4.6.x
|
41
|
+
- Fix different response from Redis#exists in different Redis versions
|
42
|
+
- All PRs:
|
43
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/275
|
44
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/287
|
45
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/309
|
46
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/299
|
47
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/314
|
48
|
+
- https://github.com/ondrejbartas/sidekiq-cron/pull/288
|
49
|
+
|
50
|
+
## 1.2.0
|
51
|
+
|
52
|
+
- Updated readme
|
53
|
+
- Fix problem with Sidekiq::Launcher and requiring it when not needed
|
54
|
+
- Better patching of Sidekiq::Launcher
|
55
|
+
- Fixed Dockerfile
|
56
|
+
|
57
|
+
## 1.1.0
|
58
|
+
|
59
|
+
- Updated readme
|
60
|
+
- Fix unit tests - changed argument error when getting invalid cron format
|
61
|
+
- When fallbacking old job enqueued time use `Time.parse` without format (so Ruby can decide best method to parse it)
|
62
|
+
- Add option `date_as_argument` which will add to your job arguments on last place `Time.now.to_f` when it was eneuqued
|
63
|
+
- Add option `description` which will allow you to add notes to your jobs so in web view you can see it
|
64
|
+
- Fixed translations
|
65
|
+
|
66
|
+
## 1.0.4
|
67
|
+
|
68
|
+
- Fix problem with upgrading to 1.0.x - parsing last enqued time didn't count with old time format stored in Redis
|
69
|
+
|
70
|
+
## 1.0.0
|
71
|
+
|
72
|
+
- 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)
|
73
|
+
- Better working with Timezones
|
74
|
+
- Translations for JA, zh-CN
|
75
|
+
- Cron without timezone are considered as UTC, to add Timezone to cron use format `* * * * * Europe/Berlin`
|
76
|
+
- 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)
|
77
|
+
|
78
|
+
## 0.6.0
|
79
|
+
|
80
|
+
- Set poller to check jobs every 30s by default (possible to override by `Sidekiq.options[:poll_interval] = 10`)
|
81
|
+
- Add group actions (enqueue, enable, disable, delete) all in web view
|
82
|
+
- Fix poller to enqueu all jobs in poll start time
|
83
|
+
- Add performance test for enqueue of jobs (10 000 jobs in less than 19s)
|
84
|
+
- Fix problem with default queue
|
85
|
+
- Remove `redis-namespace` from dependencies
|
86
|
+
- Update Ruby versions in Travis
|
87
|
+
|
88
|
+
## 0.5.0
|
89
|
+
|
90
|
+
- Add Docker support
|
91
|
+
- All crons are now evaluated in UTC
|
92
|
+
- Fix rufus scheduler & timezones problems
|
93
|
+
- Add support for Sidekiq 4.2.1
|
94
|
+
- Fix readme
|
95
|
+
- Add Russian locale
|
96
|
+
- User Rack.env in tests
|
97
|
+
- Faster enqueue of jobs
|
98
|
+
- Permit to use `ActiveJob::Base.queue_name_delimiter`
|
99
|
+
- Fix problem with multiple times enqueue #84
|
100
|
+
- Fix problem with enqueue of unknown class
|
101
|
+
|
102
|
+
## 0.4.0
|
103
|
+
|
104
|
+
- Enable to work with Sidekiq >= 4.0.0
|
105
|
+
- Fix readme
|
106
|
+
|
107
|
+
## 0.3.1
|
108
|
+
|
109
|
+
- Add CSRF tags to forms so it will work with Sidekiq >= 3.4.2
|
110
|
+
- Remove Tilt dependency
|
111
|
+
|
112
|
+
## 0.3.0
|
113
|
+
|
114
|
+
- Suport for Active Job
|
115
|
+
- Sidekiq cron web ui needs to be loaded by: require 'sidekiq/cron/web'
|
116
|
+
- Add load_from_hash! and load_from_array! which cleanup jobs before adding new ones
|
117
|
+
|
118
|
+
## 0.1.1
|
119
|
+
|
120
|
+
- Add Web front-end with enabled/disable job, enqueue now, delete job
|
121
|
+
- Add cron poller - enqueue cron jobs
|
122
|
+
- 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 '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,92 +1,125 @@
|
|
1
|
-
Sidekiq-Cron
|
2
|
-
================================================================================================================================================================================================================================================================================================================================================================================================================================================
|
1
|
+
# Sidekiq-Cron
|
3
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/sidekiq-cron.svg)](https://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](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
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.
|
23
|
-
---------------------------
|
24
|
+
## Upgrade from < 0.6 to 1.0
|
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 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.
|
26
27
|
|
27
|
-
|
28
|
-
-----------------
|
28
|
+
## Changelog
|
29
29
|
|
30
|
-
|
31
|
-
- Sidekiq 5, or 4, or 3 and greater is required (for Sidekiq < 4 use version sidekiq-cron 0.3.1)
|
30
|
+
Before upgrading to a new version, please read our [Changelog](CHANGELOG.md).
|
32
31
|
|
33
|
-
|
34
|
-
----------
|
35
|
-
before upgrading to new version, please read:
|
36
|
-
[Change Log](https://github.com/ondrejbartas/sidekiq-cron/blob/master/Changes.md)
|
32
|
+
## Installation
|
37
33
|
|
38
|
-
|
39
|
-
------------
|
34
|
+
### Requirements
|
40
35
|
|
41
|
-
|
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+
|
42
39
|
|
43
|
-
|
40
|
+
Install the gem:
|
44
41
|
|
45
|
-
|
42
|
+
```
|
43
|
+
$ gem install sidekiq-cron
|
44
|
+
```
|
46
45
|
|
46
|
+
Or add to your `Gemfile` and run `bundle install`:
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
```ruby
|
49
|
+
gem "sidekiq-cron"
|
50
|
+
```
|
50
51
|
|
52
|
+
**NOTE** If you are not using Rails, you need to add `require 'sidekiq-cron'` somewhere after `require 'sidekiq'`.
|
51
53
|
|
52
|
-
|
54
|
+
## Getting Started
|
53
55
|
|
54
|
-
|
56
|
+
**Job properties:**
|
55
57
|
|
56
58
|
```ruby
|
57
59
|
{
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
'name' => 'name_of_job', # must be uniq!
|
61
|
+
'cron' => '1 * * * *', # execute at 1 minute of every hour, ex: 12:01, 13:01, 14:01, 15:01, ... (HH:MM)
|
62
|
+
'class' => 'MyClass',
|
63
|
+
# OPTIONAL
|
64
|
+
'queue' => 'name of queue',
|
65
|
+
'args' => '[Array or Hash] of arguments which will be passed to perform method',
|
66
|
+
'date_as_argument' => true, # add the time of execution as last argument of the perform method
|
67
|
+
'active_job' => true, # enqueue job through Rails 4.2+ Active Job interface
|
68
|
+
'queue_name_prefix' => 'prefix', # Rails 4.2+ Active Job queue with prefix
|
69
|
+
'queue_name_delimiter' => '.', # Rails 4.2+ Active Job queue with custom delimiter
|
70
|
+
'description' => 'A sentence describing what work this job performs'
|
71
|
+
'status' => 'disabled' # default: enabled
|
69
72
|
}
|
70
73
|
```
|
71
74
|
|
72
|
-
### Time, cron and
|
75
|
+
### Time, cron and Sidekiq-Cron
|
73
76
|
|
74
77
|
For testing your cron notation you can use [crontab.guru](https://crontab.guru).
|
75
78
|
|
76
|
-
|
79
|
+
Sidekiq-Cron uses [Fugit](https://github.com/floraison/fugit) to parse the cronline. So please, check Fugit documentation for further information about allowed formats.
|
80
|
+
|
77
81
|
If using Rails, this is evaluated against the timezone configured in Rails, otherwise the default is UTC.
|
78
82
|
|
79
83
|
If you want to have your jobs enqueued based on a different time zone you can specify a timezone in the cronline,
|
80
84
|
like this `'0 22 * * 1-5 America/Chicago'`.
|
81
85
|
|
82
|
-
|
86
|
+
#### Natural-language formats
|
87
|
+
|
88
|
+
Since sidekiq-cron `v1.7.0`, you can use the natural-language formats supported by Fugit, such as:
|
89
|
+
|
90
|
+
```rb
|
91
|
+
"every day at five" # => '0 5 * * *'
|
92
|
+
"every 3 hours" # => '0 */3 * * *'
|
93
|
+
```
|
94
|
+
|
95
|
+
See [the relevant part of Fugit documentation](https://github.com/floraison/fugit#fugitnat) for details.
|
96
|
+
|
97
|
+
#### Second-precision (sub-minute) cronlines
|
98
|
+
|
99
|
+
In addition to the standard 5-parameter cronline format, sidekiq-cron supports scheduling jobs with second-precision using a modified 6-parameter cronline format:
|
100
|
+
|
101
|
+
`Seconds Minutes Hours Days Months DayOfWeek`
|
102
|
+
|
103
|
+
For example: `"*/30 * * * * *"` would schedule a job to run every 30 seconds.
|
104
|
+
|
105
|
+
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:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
Sidekiq[:average_scheduled_poll_interval] = 10
|
109
|
+
```
|
110
|
+
|
111
|
+
The default value at time of writing is 30 seconds. See [under the hood](#under-the-hood) for more details.
|
83
112
|
|
84
113
|
### What objects/classes can be scheduled
|
114
|
+
|
85
115
|
#### Sidekiq Worker
|
116
|
+
|
86
117
|
In this example, we are using `HardWorker` which looks like:
|
118
|
+
|
87
119
|
```ruby
|
88
120
|
class HardWorker
|
89
121
|
include Sidekiq::Worker
|
122
|
+
|
90
123
|
def perform(*args)
|
91
124
|
# do something
|
92
125
|
end
|
@@ -94,7 +127,9 @@ end
|
|
94
127
|
```
|
95
128
|
|
96
129
|
#### Active Job Worker
|
97
|
-
|
130
|
+
|
131
|
+
You can schedule `ExampleJob` which looks like:
|
132
|
+
|
98
133
|
```ruby
|
99
134
|
class ExampleJob < ActiveJob::Base
|
100
135
|
queue_as :default
|
@@ -105,11 +140,15 @@ class ExampleJob < ActiveJob::Base
|
|
105
140
|
end
|
106
141
|
```
|
107
142
|
|
108
|
-
|
109
|
-
|
143
|
+
For Active jobs you can use `symbolize_args: true` in `Sidekiq::Cron::Job.create` or in Hash configuration,
|
144
|
+
which will ensure that arguments you are passing to it will be symbolized when passed back to `perform` method in worker.
|
145
|
+
|
146
|
+
#### Adding Cron job
|
110
147
|
|
148
|
+
```ruby
|
111
149
|
class HardWorker
|
112
150
|
include Sidekiq::Worker
|
151
|
+
|
113
152
|
def perform(name, count)
|
114
153
|
# do something
|
115
154
|
end
|
@@ -130,16 +169,15 @@ else
|
|
130
169
|
puts job.errors
|
131
170
|
end
|
132
171
|
|
133
|
-
#or simple
|
134
|
-
|
172
|
+
# or simple
|
135
173
|
unless job.save
|
136
|
-
puts job.errors #will return array of errors
|
174
|
+
puts job.errors # will return array of errors
|
137
175
|
end
|
138
176
|
```
|
139
177
|
|
140
178
|
Load more jobs from hash:
|
141
|
-
```ruby
|
142
179
|
|
180
|
+
```ruby
|
143
181
|
hash = {
|
144
182
|
'name_of_job' => {
|
145
183
|
'class' => 'MyClass',
|
@@ -156,6 +194,7 @@ Sidekiq::Cron::Job.load_from_hash hash
|
|
156
194
|
```
|
157
195
|
|
158
196
|
Load more jobs from array:
|
197
|
+
|
159
198
|
```ruby
|
160
199
|
array = [
|
161
200
|
{
|
@@ -174,17 +213,17 @@ array = [
|
|
174
213
|
Sidekiq::Cron::Job.load_from_array array
|
175
214
|
```
|
176
215
|
|
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.
|
216
|
+
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
217
|
|
180
218
|
```ruby
|
181
|
-
Sidekiq::Cron::Job
|
182
|
-
Sidekiq::Cron::Job
|
219
|
+
Sidekiq::Cron::Job.load_from_hash! hash
|
220
|
+
Sidekiq::Cron::Job.load_from_array! array
|
183
221
|
```
|
184
222
|
|
185
|
-
|
223
|
+
Or from YAML (same notation as Resque-scheduler):
|
224
|
+
|
186
225
|
```yaml
|
187
|
-
#config/schedule.yml
|
226
|
+
# config/schedule.yml
|
188
227
|
|
189
228
|
my_first_job:
|
190
229
|
cron: "*/5 * * * *"
|
@@ -199,65 +238,81 @@ second_job:
|
|
199
238
|
hard: "stuff"
|
200
239
|
```
|
201
240
|
|
241
|
+
There are multiple ways to load the jobs from a YAML file
|
242
|
+
|
243
|
+
1. The gem will automatically load the jobs mentioned in `config/schedule.yml` file.
|
244
|
+
2. When you want to load jobs from a different filename, mention the filename in sidekiq configuration,
|
245
|
+
i.e. `cron_schedule_file: "config/users_schedule.yml"`
|
246
|
+
3. Load the file manually as follows
|
247
|
+
|
202
248
|
```ruby
|
203
|
-
#initializers/sidekiq.rb
|
204
|
-
|
249
|
+
# config/initializers/sidekiq.rb
|
250
|
+
|
251
|
+
Sidekiq.configure_server do |config|
|
252
|
+
config.on(:startup) do
|
253
|
+
schedule_file = "config/users_schedule.yml"
|
205
254
|
|
206
|
-
if File.exist?(schedule_file)
|
207
|
-
|
255
|
+
if File.exist?(schedule_file)
|
256
|
+
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
257
|
+
end
|
258
|
+
end
|
208
259
|
end
|
209
260
|
```
|
210
261
|
|
211
|
-
|
262
|
+
### Finding jobs
|
212
263
|
|
213
|
-
#### Finding jobs
|
214
264
|
```ruby
|
215
|
-
#return array of all jobs
|
265
|
+
# return array of all jobs
|
216
266
|
Sidekiq::Cron::Job.all
|
217
267
|
|
218
|
-
#return one job by its unique name - case sensitive
|
268
|
+
# return one job by its unique name - case sensitive
|
219
269
|
Sidekiq::Cron::Job.find "Job Name"
|
220
270
|
|
221
|
-
#return one job by its unique name - you can use hash with 'name' key
|
271
|
+
# return one job by its unique name - you can use hash with 'name' key
|
222
272
|
Sidekiq::Cron::Job.find name: "Job Name"
|
223
273
|
|
224
|
-
#if job can't be found nil is returned
|
274
|
+
# if job can't be found nil is returned
|
225
275
|
```
|
226
276
|
|
227
|
-
|
277
|
+
### Destroy jobs
|
278
|
+
|
228
279
|
```ruby
|
229
|
-
#
|
280
|
+
# destroy all jobs
|
230
281
|
Sidekiq::Cron::Job.destroy_all!
|
231
282
|
|
232
|
-
#destroy job by its name
|
283
|
+
# destroy job by its name
|
233
284
|
Sidekiq::Cron::Job.destroy "Job Name"
|
234
285
|
|
235
|
-
#destroy found job
|
286
|
+
# destroy found job
|
236
287
|
Sidekiq::Cron::Job.find('Job name').destroy
|
237
288
|
```
|
238
289
|
|
239
|
-
|
290
|
+
### Work with job
|
291
|
+
|
240
292
|
```ruby
|
241
293
|
job = Sidekiq::Cron::Job.find('Job name')
|
242
294
|
|
243
|
-
#disable cron scheduling
|
295
|
+
# disable cron scheduling
|
244
296
|
job.disable!
|
245
297
|
|
246
|
-
#enable cron scheduling
|
298
|
+
# enable cron scheduling
|
247
299
|
job.enable!
|
248
300
|
|
249
|
-
#get status of job:
|
301
|
+
# get status of job:
|
250
302
|
job.status
|
251
303
|
# => enabled/disabled
|
252
304
|
|
253
|
-
#enqueue job right now!
|
305
|
+
# enqueue job right now!
|
254
306
|
job.enque!
|
255
307
|
```
|
256
308
|
|
257
|
-
How to start scheduling?
|
309
|
+
### How to start scheduling?
|
310
|
+
|
258
311
|
Just start Sidekiq workers by running:
|
259
312
|
|
260
|
-
|
313
|
+
```
|
314
|
+
$ sidekiq
|
315
|
+
```
|
261
316
|
|
262
317
|
### Web UI for Cron Jobs
|
263
318
|
|
@@ -265,68 +320,43 @@ If you are using Sidekiq's web UI and you would like to add cron jobs too to thi
|
|
265
320
|
add `require 'sidekiq/cron/web'` after `require 'sidekiq/web'`.
|
266
321
|
|
267
322
|
With this, you will get:
|
268
|
-
![Web UI](https://github.com/ondrejbartas/sidekiq-cron/raw/master/examples/web-cron-ui.png)
|
269
|
-
|
270
|
-
### Forking Processes
|
271
323
|
|
272
|
-
|
273
|
-
before the process forks, causing the following exception
|
274
|
-
|
275
|
-
Redis::InheritedError: Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking.
|
276
|
-
|
277
|
-
to occur. To avoid this, wrap your job creation in the call to `Sidekiq.configure_server`:
|
278
|
-
|
279
|
-
```ruby
|
280
|
-
Sidekiq.configure_server do |config|
|
281
|
-
schedule_file = "config/schedule.yml"
|
282
|
-
|
283
|
-
if File.exist?(schedule_file)
|
284
|
-
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)
|
285
|
-
end
|
286
|
-
end
|
287
|
-
```
|
288
|
-
|
289
|
-
Note that this API is only available in Sidekiq 3.x.x.
|
324
|
+
![Web UI](examples/web-cron-ui.jpeg)
|
290
325
|
|
291
326
|
## Under the hood
|
292
327
|
|
293
328
|
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
329
|
|
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
|
330
|
+
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
331
|
|
297
332
|
Sidekiq-Cron is checking jobs to be enqueued every 30s by default, you can change it by setting:
|
298
|
-
```
|
299
|
-
Sidekiq.options[:poll_interval] = 10
|
300
|
-
```
|
301
333
|
|
302
|
-
|
334
|
+
```ruby
|
335
|
+
Sidekiq[:average_scheduled_poll_interval] = 10
|
336
|
+
```
|
303
337
|
|
304
|
-
|
305
|
-
* [@7korobi](https://github.com/7korobi)
|
306
|
-
* [@antulik](https://github.com/antulik)
|
307
|
-
* [@felixbuenemann](https://github.com/felixbuenemann)
|
308
|
-
* [@gstark](https://github.com/gstark)
|
309
|
-
* [@RajRoR](https://github.com/RajRoR)
|
310
|
-
* [@romeuhcf](https://github.com/romeuhcf)
|
311
|
-
* [@siruguri](https://github.com/siruguri)
|
312
|
-
* [@Soliah](https://github.com/Soliah)
|
313
|
-
* [@stephankaag](https://github.com/stephankaag)
|
314
|
-
* [@sue445](https://github.com/sue445)
|
315
|
-
* [@sylg](https://github.com/sylg)
|
316
|
-
* [@tmeinlschmidt](https://github.com/tmeinlschmidt)
|
317
|
-
* [@zerobearing2](https://github.com/zerobearing2)
|
338
|
+
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.
|
318
339
|
|
340
|
+
## Contributing
|
319
341
|
|
320
|
-
|
342
|
+
**Thanks to all [contributors](https://github.com/ondrejbartas/sidekiq-cron/graphs/contributors), you’re awesome and this wouldn’t be possible without you!**
|
321
343
|
|
322
344
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
323
345
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
324
346
|
* Fork the project.
|
325
347
|
* Start a feature/bugfix branch.
|
326
348
|
* Commit and push until you are happy with your contribution.
|
327
|
-
* Make sure to add tests for it. This is important so
|
328
|
-
*
|
349
|
+
* Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
|
350
|
+
* Open a pull request!
|
351
|
+
|
352
|
+
### Testing
|
353
|
+
|
354
|
+
You can execute the test suite by running:
|
355
|
+
|
356
|
+
```
|
357
|
+
$ bundle exec rake test
|
358
|
+
```
|
329
359
|
|
330
|
-
##
|
360
|
+
## License
|
331
361
|
|
332
|
-
Copyright (c) 2013 Ondrej Bartas. See LICENSE.txt for further details.
|
362
|
+
Copyright (c) 2013 Ondrej Bartas. See [LICENSE](LICENSE.txt) for further details.
|
data/Rakefile
CHANGED
@@ -1,43 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler/setup'
|
5
|
-
require 'bundler'
|
6
|
-
|
7
|
-
begin
|
8
|
-
Bundler.setup(:default, :development)
|
9
|
-
rescue Bundler::BundlerError => e
|
10
|
-
$stderr.puts e.message
|
11
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
-
exit e.status_code
|
13
|
-
end
|
14
|
-
require 'rake'
|
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
|
-
#TESTING
|
31
|
-
|
32
|
-
task :doc do
|
33
|
-
system 'sdoc -N .'
|
34
|
-
end
|
35
|
-
|
1
|
+
require 'bundler/gem_tasks'
|
36
2
|
require 'rake/testtask'
|
3
|
+
|
37
4
|
task :default => :test
|
38
5
|
|
39
6
|
Rake::TestTask.new(:test) do |t|
|
40
|
-
t.test_files = FileList['test/
|
7
|
+
t.test_files = FileList['test/unit/**/*_test.rb', 'test/integration/**/*_test.rb']
|
41
8
|
t.warning = false
|
42
9
|
t.verbose = false
|
43
10
|
end
|
@@ -49,12 +16,6 @@ namespace :test do
|
|
49
16
|
t.verbose = false
|
50
17
|
end
|
51
18
|
|
52
|
-
Rake::TestTask.new(:functional) do |t|
|
53
|
-
t.test_files = FileList['test/functional/**/*_test.rb']
|
54
|
-
t.warning = false
|
55
|
-
t.verbose = false
|
56
|
-
end
|
57
|
-
|
58
19
|
Rake::TestTask.new(:integration) do |t|
|
59
20
|
t.test_files = FileList['test/integration/**/*_test.rb']
|
60
21
|
t.warning = false
|