-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a model which will replace the worker type constant. It seeds the table based on the leaf subclasses of MiqWorker and each worker class needs to define its own attributes, specifically its priority in the kill order and bundler groups. This allows new workers to be added by simply adding a new subclass of MiqWorker rather than maintaining a list of worker classes in the core repo. Additionally this brings us closer to the ability to run a separate process that will access the database and determine which workers should be running on which servers, all outside of the main application code-base.
- Loading branch information
Showing
20 changed files
with
121 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,8 @@ def friendly_name | |
end | ||
end | ||
end | ||
|
||
def self.kill_priority | ||
130 | ||
end | ||
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
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 |
---|---|---|
|
@@ -13,4 +13,8 @@ def friendly_name | |
def self.supports_container? | ||
true | ||
end | ||
|
||
def self.kill_priority | ||
10 | ||
end | ||
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
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 |
---|---|---|
|
@@ -12,4 +12,8 @@ def self.queue_priority | |
def self.supports_container? | ||
true | ||
end | ||
|
||
def self.kill_priority | ||
90 | ||
end | ||
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 |
---|---|---|
|
@@ -16,4 +16,8 @@ def friendly_name | |
def self.supports_container? | ||
true | ||
end | ||
|
||
def self.kill_priority | ||
150 | ||
end | ||
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
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 |
---|---|---|
|
@@ -13,4 +13,8 @@ class MiqScheduleWorker < MiqWorker | |
def self.supports_container? | ||
true | ||
end | ||
|
||
def self.kill_priority | ||
80 | ||
end | ||
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class MiqWorkerType < ApplicationRecord | ||
EXCLUDED_CLASS_NAMES = %w[ManageIQ::Providers::BaseManager::OperationsWorker].freeze | ||
|
||
scope :in_kill_order, -> { order(:kill_priority => :asc) } | ||
|
||
def self.seed | ||
transaction do | ||
classes_for_seed.each { |klass| seed_worker(klass) } | ||
end | ||
end | ||
|
||
private_class_method def self.classes_for_seed | ||
MiqWorker.descendants.select { |w| w.subclasses.empty? } - EXCLUDED_CLASS_NAMES.map(&:constantize) | ||
end | ||
|
||
private_class_method def self.seed_worker(klass) | ||
instance = find_or_initialize_by(:worker_type => klass.name) | ||
|
||
instance.update!( | ||
:bundler_groups => klass.bundler_groups, | ||
:kill_priority => klass.kill_priority | ||
) | ||
end | ||
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
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ class EvmDatabase | |
Zone | ||
MiqServer | ||
ServerRole | ||
MiqWorkerType | ||
Tenant | ||
MiqProductFeature | ||
MiqUserRole | ||
|
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,21 @@ | ||
describe MiqWorkerType do | ||
describe ".seed" do | ||
before { described_class.seed } | ||
|
||
it "doesn't create a row for excluded classes" do | ||
expect(described_class.count).to be > 0 | ||
expect(described_class.pluck(:worker_type)).not_to include(*described_class::EXCLUDED_CLASS_NAMES) | ||
end | ||
|
||
it "correctly creates records for workers" do | ||
generic_worker = described_class.find_by(:worker_type => "MiqGenericWorker") | ||
ui_worker = described_class.find_by(:worker_type => "MiqUiWorker") | ||
|
||
expect(generic_worker.bundler_groups).to match_array(MiqGenericWorker.bundler_groups) | ||
expect(generic_worker.kill_priority).to eq(MiqGenericWorker.kill_priority) | ||
|
||
expect(ui_worker.bundler_groups).to match_array(MiqUiWorker.bundler_groups) | ||
expect(ui_worker.kill_priority).to eq(MiqUiWorker.kill_priority) | ||
end | ||
end | ||
end |