sidekiq-scheduler 0.7 → 1.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 +8 -8
- data/README.md +40 -39
- data/lib/sidekiq-scheduler.rb +23 -1
- data/lib/sidekiq-scheduler/manager.rb +2 -2
- data/lib/sidekiq-scheduler/version.rb +1 -1
- metadata +4 -10
- data/bin/sidekiq-scheduler +0 -16
- data/lib/sidekiq-scheduler/cli.rb +0 -35
- data/lib/sidekiq-scheduler/testing.rb +0 -33
- data/test/cli_test.rb +0 -26
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTgyMGVlOTk3ZGM2ZjQ0ZWI0ZWFkNzViYTU1Mjg2N2ZiZGU4NmI5Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDA0ZTJmZGU0ZDdlMDBmOGM0ODUxNWIyNDRkMjRjYmQ2ZTMyYjJmMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDYxNjQ1ZGVlNGFlNjJiYWIxODQ0NTdkYTEyNDc2YmE4Zjk5MjUzYjdhOTk0
|
10
|
+
NjY2NDZjOWEyYTAyZTQzYjUyMTE5MmU2MzcxMmFjMzJkZWVkMmZhNzFjOTM4
|
11
|
+
ZDY4MTJhODMxZjE1MjgyZTgxM2NjMTYxNTJkMmFiMjhhMTk5MjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGU0ZDVmZmE0Yjk3YjRjZTFjOWE1YTA1MmM3M2E1YTI3MDFkODdhZDFlMWUz
|
14
|
+
MzliNWM1MzAyNWM2ZWY5YzUzMzc2NDNlMzA5M2UzYWFiY2ZhNTA3MmYwOTU0
|
15
|
+
M2RiYzU1ZTFlOTFjNDdmMDRkZjBiYTcxNWIzYjU3NTAwOTM5M2I=
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# SidekiqScheduler
|
2
2
|
|
3
|
+
## Note
|
4
|
+
|
5
|
+
The master branch and releases from 1.0 are compatible with sidekiq ~> 3, for sidekiq ~> 2 support
|
6
|
+
use versions ~> 0.
|
7
|
+
|
3
8
|
## Description
|
4
9
|
|
5
10
|
sidekiq-scheduler is an extension to [Sidekiq](http://github.com/mperham/sidekiq)
|
@@ -15,37 +20,32 @@ details on individual methods, you might want to try the [rdoc](http://rdoc.info
|
|
15
20
|
|
16
21
|
## Installation
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
Add this to your Gemfile:
|
24
|
+
```ruby
|
25
|
+
gem 'sidekiq-scheduler', '~> 1'
|
26
|
+
```
|
27
|
+
|
28
|
+
If you are using rails you are set
|
29
|
+
|
30
|
+
If you are not using rails create a file with this content:
|
31
|
+
```ruby
|
32
|
+
require 'sidekiq-scheduler'
|
33
|
+
```
|
20
34
|
|
21
|
-
|
22
|
-
|
35
|
+
and the execute:
|
36
|
+
```sh
|
37
|
+
sidekiq -r created_file_path.rb
|
38
|
+
```
|
23
39
|
|
24
|
-
|
25
|
-
|
26
|
-
this will result in 25 worker threads being available on the scheduler
|
27
|
-
node but all normal configuration options apply.
|
40
|
+
Look at [Loading the schedule][https://github.com/moove-it/sidekiq-scheduler/tree/0.x#loading-the-schedule]
|
41
|
+
for information on how to load your schedule.
|
28
42
|
|
29
|
-
|
30
|
-
parsing provided by sidekiq you will need to use a configuration file to
|
31
|
-
override the scheduler options.
|
43
|
+
You can add sidekiq-scheduler configuration options to sidekiq.yml config file.
|
32
44
|
Available options are:
|
33
45
|
|
34
46
|
:schedule: <the schedule to be run>
|
35
47
|
:dynamic: <if true the schedule can we modified in runtime>
|
36
48
|
|
37
|
-
The scheduling thread will sleep this many seconds between looking for
|
38
|
-
jobs that need moving to the worker queue. The default is 5 seconds
|
39
|
-
which should be fast enough for almost all uses.
|
40
|
-
|
41
|
-
NOTE: You DO NOT want to run more than one instance of the scheduler. Doing
|
42
|
-
so will result in the same job being queued multiple times. You only need one
|
43
|
-
instance of the scheduler running per application, regardless of number of servers.
|
44
|
-
|
45
|
-
NOTE: If the scheduler thread goes down for whatever reason, the delayed items
|
46
|
-
that should have fired during the outage will fire once the scheduler is
|
47
|
-
started back up again (even if it is on a new machine).
|
48
|
-
|
49
49
|
## Scheduled Jobs (Recurring Jobs)
|
50
50
|
|
51
51
|
Scheduled (or recurring) jobs are logically no different than a standard cron
|
@@ -94,20 +94,31 @@ seconds past the minute).
|
|
94
94
|
A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
|
95
95
|
for handling the heavy lifting of the actual scheduling engine.
|
96
96
|
|
97
|
+
|
97
98
|
### Loading the schedule
|
98
99
|
|
99
100
|
Let's assume your scheduled jobs are defined in a file called "config/scheduler.yml" under your Rails project,
|
100
101
|
you could create a Rails initializer called "config/initializer/scheduler.rb" which would load the job definitions:
|
101
102
|
|
102
|
-
|
103
|
-
|
103
|
+
```ruby
|
104
|
+
require 'sidekiq/scheduler'
|
105
|
+
Sidekiq.schedule = YAML.load_file(File.expand_path("../../../config/scheduler.yml",__FILE__))
|
106
|
+
```
|
104
107
|
|
105
108
|
If you were running a non Rails project you should add code to load the workers classes before loading the schedule.
|
106
109
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
110
|
+
```ruby
|
111
|
+
require 'sidekiq/scheduler'
|
112
|
+
Dir[File.expand_path('../lib/workers/*.rb',__FILE__)].each do |file| load file; end
|
113
|
+
Sidekiq.schedule = YAML.load_file(File.expand_path("../../../config/scheduler.yml",__FILE__))
|
114
|
+
```
|
115
|
+
|
116
|
+
You can also put your schedule information inside sidekiq.yml and load it with:
|
117
|
+
|
118
|
+
```sh
|
119
|
+
sidekiq -C ./config/sidekiq.yml
|
120
|
+
```
|
121
|
+
|
111
122
|
### Time zones
|
112
123
|
|
113
124
|
Note that if you use the cron syntax, this will be interpreted as in the server time zone
|
@@ -125,16 +136,6 @@ from the `config.time_zone` value, make sure it's the right format, e.g. with:
|
|
125
136
|
|
126
137
|
A future version of sidekiq-scheduler may do this for you.
|
127
138
|
|
128
|
-
## Using with Testing
|
129
|
-
|
130
|
-
Sidekiq uses a jobs array on workers for testing, which is supported by sidekiq-scheduler when you require the test code:
|
131
|
-
|
132
|
-
require 'sidekiq/testing'
|
133
|
-
require 'sidekiq-scheduler/testing'
|
134
|
-
|
135
|
-
MyWorker.perform_in 5, 'arg1'
|
136
|
-
puts MyWorker.jobs.inspect
|
137
|
-
|
138
139
|
## Note on Patches / Pull Requests
|
139
140
|
|
140
141
|
* Fork the project.
|
data/lib/sidekiq-scheduler.rb
CHANGED
@@ -1,2 +1,24 @@
|
|
1
1
|
require 'sidekiq'
|
2
|
-
|
2
|
+
|
3
|
+
require_relative 'sidekiq-scheduler/version'
|
4
|
+
require_relative 'sidekiq-scheduler/manager'
|
5
|
+
|
6
|
+
Sidekiq.configure_server do |config|
|
7
|
+
|
8
|
+
config.on(:startup) do
|
9
|
+
scheduler_options = {
|
10
|
+
:scheduler => config.options.fetch(:scheduler, true),
|
11
|
+
:dynamic => config.options.fetch(:dynamic, false),
|
12
|
+
:schedule => config.options.fetch(:schedule, nil)
|
13
|
+
}
|
14
|
+
|
15
|
+
schedule_manager = SidekiqScheduler::Manager.new(scheduler_options)
|
16
|
+
config.options[:schedule_manager] = schedule_manager
|
17
|
+
config.options[:schedule_manager].start
|
18
|
+
end
|
19
|
+
|
20
|
+
config.on(:shutdown) do
|
21
|
+
config.options[:schedule_manager].stop
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -28,8 +28,8 @@ module SidekiqScheduler
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def start
|
31
|
-
#Load the schedule into rufus
|
32
|
-
#If dynamic is set, load that schedule otherwise use normal load
|
31
|
+
# Load the schedule into rufus
|
32
|
+
# If dynamic is set, load that schedule otherwise use normal load
|
33
33
|
if @enabled && Sidekiq::Scheduler.dynamic
|
34
34
|
Sidekiq::Scheduler.reload_schedule!
|
35
35
|
elsif @enabled
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0
|
4
|
+
version: '1.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morton Jonuschat
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ~>
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '3'
|
21
21
|
- - ! '>='
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '2.12'
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
30
|
+
version: '3'
|
31
31
|
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.12'
|
@@ -161,25 +161,20 @@ description: Light weight job scheduling extension for Sidekiq that adds support
|
|
161
161
|
queueing items in the future.
|
162
162
|
email:
|
163
163
|
- adrian_g171@hotmail.com
|
164
|
-
executables:
|
165
|
-
- sidekiq-scheduler
|
164
|
+
executables: []
|
166
165
|
extensions: []
|
167
166
|
extra_rdoc_files: []
|
168
167
|
files:
|
169
168
|
- MIT-LICENSE
|
170
169
|
- README.md
|
171
170
|
- Rakefile
|
172
|
-
- bin/sidekiq-scheduler
|
173
171
|
- lib/sidekiq-scheduler.rb
|
174
172
|
- lib/sidekiq-scheduler/capistrano.rb
|
175
|
-
- lib/sidekiq-scheduler/cli.rb
|
176
173
|
- lib/sidekiq-scheduler/manager.rb
|
177
174
|
- lib/sidekiq-scheduler/schedule.rb
|
178
|
-
- lib/sidekiq-scheduler/testing.rb
|
179
175
|
- lib/sidekiq-scheduler/version.rb
|
180
176
|
- lib/sidekiq/scheduler.rb
|
181
177
|
- lib/tasks/sidekiq-scheduler_tasks.rake
|
182
|
-
- test/cli_test.rb
|
183
178
|
- test/config.yml
|
184
179
|
- test/fake_env.rb
|
185
180
|
- test/lib/sidekiq/scheduler_test.rb
|
@@ -219,4 +214,3 @@ test_files:
|
|
219
214
|
- test/lib/sidekiq/scheduler_test.rb
|
220
215
|
- test/fake_env.rb
|
221
216
|
- test/config.yml
|
222
|
-
- test/cli_test.rb
|
data/bin/sidekiq-scheduler
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'sidekiq/cli'
|
4
|
-
|
5
|
-
begin
|
6
|
-
cli = Sidekiq::CLI.instance
|
7
|
-
cli.parse
|
8
|
-
|
9
|
-
require 'sidekiq-scheduler/cli'
|
10
|
-
cli.run
|
11
|
-
rescue => e
|
12
|
-
raise e if $DEBUG
|
13
|
-
STDERR.puts e.message
|
14
|
-
STDERR.puts e.backtrace.join("\n")
|
15
|
-
exit 1
|
16
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'sidekiq/cli'
|
2
|
-
|
3
|
-
require 'sidekiq-scheduler/manager'
|
4
|
-
|
5
|
-
module SidekiqScheduler
|
6
|
-
module CLI
|
7
|
-
|
8
|
-
def self.included(base)
|
9
|
-
base.class_eval do
|
10
|
-
alias_method :run_manager, :run
|
11
|
-
alias_method :run, :run_scheduler
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def run_scheduler
|
16
|
-
scheduler_options = { :scheduler => true, :schedule => nil }
|
17
|
-
scheduler_options.merge!(options)
|
18
|
-
|
19
|
-
if options[:config_file]
|
20
|
-
file_options = YAML.load_file(options[:config_file])
|
21
|
-
options.merge!(file_options)
|
22
|
-
options.delete(:config_file)
|
23
|
-
parse_queues(options, options.delete(:queues) || [])
|
24
|
-
end
|
25
|
-
|
26
|
-
scheduler = SidekiqScheduler::Manager.new(scheduler_options)
|
27
|
-
scheduler.start
|
28
|
-
run_manager
|
29
|
-
scheduler.stop
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
Sidekiq::CLI.send(:include, SidekiqScheduler::CLI)
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'sidekiq/testing'
|
2
|
-
|
3
|
-
module SidekiqScheduler
|
4
|
-
module Worker
|
5
|
-
module ClassMethods
|
6
|
-
alias_method :perform_at_old, :perform_at
|
7
|
-
def perform_at(timestamp, *args)
|
8
|
-
jobs << { 'class' => self.name, 'timestamp' => timestamp.to_i, 'args' => args }
|
9
|
-
true
|
10
|
-
end
|
11
|
-
|
12
|
-
alias_method :perform_in_old, :perform_in
|
13
|
-
def perform_in(seconds_from_now, *args)
|
14
|
-
timestamp = Time.now + seconds_from_now
|
15
|
-
jobs << { 'class' => self.name, 'timestamp' => timestamp.to_i, 'args' => args }
|
16
|
-
end
|
17
|
-
|
18
|
-
alias_method :remove_delayed_old, :remove_delayed
|
19
|
-
def remove_delayed(*args)
|
20
|
-
old_jobcount = jobs.size
|
21
|
-
jobs.reject! { |job| job["class"] == self.name && job["args"] == args }
|
22
|
-
old_jobcount - jobs.size
|
23
|
-
end
|
24
|
-
|
25
|
-
alias_method :remove_delayed_from_timestamp_old, :remove_delayed_from_timestamp
|
26
|
-
def remove_delayed_from_timestamp(timestamp, *args)
|
27
|
-
old_jobcount = jobs.size
|
28
|
-
jobs.reject! { |job| job["class"] == self.name && job["timestamp"] == timestamp.to_i && job["args"] == args }
|
29
|
-
old_jobcount - jobs.size
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/test/cli_test.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'sidekiq-scheduler/cli'
|
3
|
-
require 'tempfile'
|
4
|
-
|
5
|
-
class CliTest < Minitest::Test
|
6
|
-
|
7
|
-
describe 'with cli' do
|
8
|
-
|
9
|
-
before do
|
10
|
-
Celluloid.boot
|
11
|
-
@cli = Sidekiq::CLI.instance
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'with config file' do
|
15
|
-
before do
|
16
|
-
@cli.parse(['sidekiq', '-C', './test/config.yml'])
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'sets the resolution of the scheduler timer' do
|
20
|
-
assert_equal 30, Sidekiq.options[:resolution]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|