-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: add support for multiple workers
Previously mini scheduler was tied to a single runner. This was somewhat arbitrary as all the internals were designed with multi runner support. This unlocks the ability to run multiple threads for the jobs.
- Loading branch information
1 parent
5235fff
commit 7cf0f99
Showing
6 changed files
with
106 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module MiniScheduler | ||
VERSION = "0.11.0" | ||
VERSION = "0.12.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
# encoding: utf-8 | ||
|
||
if ENV["SLOW"] | ||
|
||
class FastJob | ||
extend ::MiniScheduler::Schedule | ||
every 1.second | ||
|
||
def self.runs=(val) | ||
@runs = val | ||
end | ||
|
||
def self.runs | ||
@runs ||= 0 | ||
end | ||
|
||
def perform | ||
sleep 0.001 | ||
self.class.runs += 1 | ||
end | ||
end | ||
|
||
class SlowJob | ||
extend ::MiniScheduler::Schedule | ||
every 5.second | ||
|
||
def self.runs=(val) | ||
@runs = val | ||
end | ||
|
||
def self.runs | ||
@runs ||= 0 | ||
end | ||
|
||
def perform | ||
sleep 5 | ||
self.class.runs += 1 | ||
end | ||
end | ||
|
||
describe MiniScheduler::Manager do | ||
|
||
let(:redis) { MockRedis.new } | ||
|
||
it "can correctly operate with multiple workers" do | ||
MiniScheduler.configure do |config| | ||
config.redis = redis | ||
end | ||
|
||
manager = MiniScheduler::Manager.new(enable_stats: false, workers: 2) | ||
|
||
sched = manager.schedule_info(FastJob) | ||
# we jitter start times, this bypasses it | ||
sched.next_run = Time.now + 0.1 | ||
sched.schedule! | ||
|
||
sched = manager.schedule_info(SlowJob) | ||
# we jitter start times, this bypasses it | ||
sched.next_run = Time.now + 0.1 | ||
sched.schedule! | ||
|
||
10.times do | ||
manager.tick | ||
sleep 1 | ||
end | ||
|
||
manager.stop! | ||
|
||
expect(FastJob.runs).to be > 5 | ||
expect(SlowJob.runs).to be > 0 | ||
|
||
end | ||
end | ||
end |