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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d84546928a92e57ef72f4af8a5125c6d1ac12cddd32cd3b4203f819754b8c754
4
- data.tar.gz: a5a8406b9c15ef74ea8729991137ebcc37f80ea4a367e7f9ce5da11cc6620ab9
3
+ metadata.gz: 324689a31f8f494316a58699381894fa31d99567e5f93c58c29eae0f3bcc6fcc
4
+ data.tar.gz: aeababfda51718aa05b3f1738dac50b9e24f25653133cc1d36fe434265a47e5e
5
5
  SHA512:
6
- metadata.gz: c8b0a9e24bc8b785ffb0a4a01b4cef24a403604ec92851d862533b306ceab23008dad5419a7833e7c4f625d32206604f3308360db8942f61b7c254b0c2603a1d
7
- data.tar.gz: e2f99830e4ede44cd66fba4d206cb6d2c16e712e0df30888a8677ec8b5ac6db78d3538da92769985cc84e8f211025f1682c51aa41716a034e39a5b49cdeeb56a
6
+ metadata.gz: 2e7dec4a84b48fba2497e17250bbf1d571780d5ce3eccf2d8e9740f62f135feac5c3c176296ff8debb08381b2a0e9f7cd7c27553091f13d19e854dda4ae05266
7
+ data.tar.gz: d7b9c791395231b3db2fdfd231754ccb621c8b542b1da648963aed9d3aebcbd324a7d9bd14a9e057cf597e62aa752ffca171302c784e6dda5f64e2078debd42d
@@ -1,3 +1,7 @@
1
+ # 0.12.0 - 29-08-2019
2
+
3
+ - Add support for multiple workers which allows avoiding queue starvation
4
+
1
5
  # 0.11.0 - 24-06-2019
2
6
 
3
7
  - Correct situation where distributed mutex could end in a tight loop when
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:
@@ -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
- @thread = Thread.new do
33
- while !@stopped
34
- process_queue
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
- @thread.kill
134
+ @threads.each(&:kill)
132
135
  end
133
136
 
134
- @thread.join
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]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniScheduler
4
- VERSION = "0.11.0"
4
+ VERSION = "0.12.0"
5
5
  end
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.11.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-06-24 00:00:00.000000000 Z
12
+ date: 2019-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq