mini_scheduler 0.11.0 → 0.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 +4 -0
- data/README.md +14 -0
- data/lib/mini_scheduler.rb +2 -2
- data/lib/mini_scheduler/manager.rb +10 -6
- data/lib/mini_scheduler/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 324689a31f8f494316a58699381894fa31d99567e5f93c58c29eae0f3bcc6fcc
|
4
|
+
data.tar.gz: aeababfda51718aa05b3f1738dac50b9e24f25653133cc1d36fe434265a47e5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e7dec4a84b48fba2497e17250bbf1d571780d5ce3eccf2d8e9740f62f135feac5c3c176296ff8debb08381b2a0e9f7cd7c27553091f13d19e854dda4ae05266
|
7
|
+
data.tar.gz: d7b9c791395231b3db2fdfd231754ccb621c8b542b1da648963aed9d3aebcbd324a7d9bd14a9e057cf597e62aa752ffca171302c784e6dda5f64e2078debd42d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,6 +30,20 @@ In a Rails application, create files needed in your application to configure min
|
|
30
30
|
|
31
31
|
An initializer is created named `config/initializers/mini_scheduler.rb` which lists all the configuration options.
|
32
32
|
|
33
|
+
## Configuring MiniScheduler
|
34
|
+
|
35
|
+
By default each instance of MiniScheduler will run with a single worker. To amend this behavior:
|
36
|
+
|
37
|
+
```
|
38
|
+
if Sidekiq.server? && defined?(Rails)
|
39
|
+
Rails.application.config.after_initialize do
|
40
|
+
MiniScheduler.start(workers: 5)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
This is useful for cases where you have extremely long running tasks that you would prefer did not starve.
|
46
|
+
|
33
47
|
## Usage
|
34
48
|
|
35
49
|
Create jobs with a recurring schedule like this:
|
data/lib/mini_scheduler.rb
CHANGED
@@ -52,11 +52,11 @@ module MiniScheduler
|
|
52
52
|
@skip_schedule
|
53
53
|
end
|
54
54
|
|
55
|
-
def self.start
|
55
|
+
def self.start(workers: 1)
|
56
56
|
schedules = Manager.discover_schedules
|
57
57
|
|
58
58
|
Manager.discover_queues.each do |queue|
|
59
|
-
manager = Manager.new(queue: queue)
|
59
|
+
manager = Manager.new(queue: queue, workers: workers)
|
60
60
|
|
61
61
|
schedules.each do |schedule|
|
62
62
|
if schedule.queue == queue
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module MiniScheduler
|
4
4
|
class Manager
|
5
|
-
attr_accessor :random_ratio, :redis, :enable_stats, :queue
|
5
|
+
attr_accessor :random_ratio, :redis, :enable_stats, :queue, :workers
|
6
6
|
|
7
7
|
class Runner
|
8
8
|
def initialize(manager)
|
@@ -29,9 +29,12 @@ module MiniScheduler
|
|
29
29
|
sleep (@manager.keep_alive_duration / 2)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
@
|
33
|
-
|
34
|
-
|
32
|
+
@threads = []
|
33
|
+
manager.workers.times do
|
34
|
+
@threads << Thread.new do
|
35
|
+
while !@stopped
|
36
|
+
process_queue
|
37
|
+
end
|
35
38
|
end
|
36
39
|
end
|
37
40
|
end
|
@@ -128,10 +131,10 @@ module MiniScheduler
|
|
128
131
|
|
129
132
|
kill_thread = Thread.new do
|
130
133
|
sleep 0.5
|
131
|
-
@
|
134
|
+
@threads.each(&:kill)
|
132
135
|
end
|
133
136
|
|
134
|
-
@
|
137
|
+
@threads.each(&:join)
|
135
138
|
kill_thread.kill
|
136
139
|
kill_thread.join
|
137
140
|
end
|
@@ -171,6 +174,7 @@ module MiniScheduler
|
|
171
174
|
|
172
175
|
def initialize(options = nil)
|
173
176
|
@queue = options && options[:queue] || "default"
|
177
|
+
@workers = options && options[:workers] || 1
|
174
178
|
@redis = MiniScheduler.redis
|
175
179
|
@random_ratio = 0.1
|
176
180
|
unless options && options[:skip_runner]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|