Skip to content

Commit

Permalink
Use a method for after_initialize rather than a block
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Feb 27, 2024
1 parent 0d787ce commit f54cc63
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class MiqWorker < ApplicationRecord
include SystemdCommon
include UuidMixin

before_destroy :error_out_tasks_with_active_queue_message, :log_destroy_of_worker_messages
after_initialize :set_system_uid
before_destroy :error_out_tasks_with_active_queue_message, :log_destroy_of_worker_messages

belongs_to :miq_server
has_many :messages, :as => :handler, :class_name => 'MiqQueue'
Expand Down Expand Up @@ -40,10 +41,6 @@ class MiqWorker < ApplicationRecord

PROCESS_TITLE_PREFIX = "MIQ:".freeze

after_initialize do |worker|
worker.system_uid = worker.unit_name if worker.systemd_worker?
end

def self.atShutdown
stop_workers
end
Expand Down Expand Up @@ -487,6 +484,10 @@ def clean_active_messages
end
end

private def set_system_uid
self.system_uid = unit_name if systemd_worker?
end

private def error_out_tasks_with_active_queue_message
message = "Task Handler: [#{friendly_name}] ID [#{id}] has been deleted!"
processed_messages.includes(:miq_task).where.not(:miq_task_id => nil).each do |m|
Expand Down

0 comments on commit f54cc63

Please sign in to comment.