Skip to content

Commit

Permalink
Move callbacks before save for #changed? and #changes?
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Dec 6, 2022
1 parent eb74c6c commit 0015fd8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ def edit_with_params(params, endpoints, authentications)
endpoints_changed ||= ems.endpoints.any?(&:changed?)
authentications_changed ||= ems.authentications.any?(&:changed?)

after_update_endpoints if endpoints_changed
after_update_authentication if authentications_changed

ems.provider.save! if ems.provider.present? && ems.provider.changed?
ems.save!
end

after_update_endpoints if endpoints_changed
after_update_authentication if authentications_changed
end
end

Expand Down Expand Up @@ -920,14 +920,14 @@ def stop_event_monitor_queue
end

def stop_event_monitor_queue_on_change
if event_monitor_class && !self.new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
if event_monitor_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
_log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
stop_event_monitor_queue
end
end

def stop_event_monitor_queue_on_credential_change
if event_monitor_class && !self.new_record? && self.credentials_changed?
if event_monitor_class && !new_record? && default_authentication.changed?
_log.info("EMS: [#{name}], Credentials have changed, stopping Event Monitor. It will be restarted by the WorkerMonitor.")
stop_event_monitor_queue
end
Expand Down Expand Up @@ -984,14 +984,14 @@ def stop_refresh_worker_queue
end

def stop_refresh_worker_queue_on_change
if refresh_worker_class && !self.new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
if refresh_worker_class && !new_record? && default_endpoint.changed.include_any?("hostname", "ipaddress")
_log.info("EMS: [#{name}], Hostname or IP address has changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.")
stop_refresh_worker_queue
end
end

def stop_refresh_worker_queue_on_credential_change
if refresh_worker_class && !self.new_record? && self.credentials_changed?
if refresh_worker_class && !new_record? && default_authentication.changed?
_log.info("EMS: [#{name}], Credentials have changed, stopping Refresh Worker. It will be restarted by the WorkerMonitor.")
stop_refresh_worker_queue
end
Expand Down
12 changes: 12 additions & 0 deletions spec/models/ext_management_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,12 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first)

ems.edit_with_params(params, endpoints, authentications)
end

it "stops the event monitor" do
expect(ems).to receive(:stop_event_monitor_queue)

ems.edit_with_params(params, endpoints, authentications)
end
end

context "adding an authentication" do
Expand Down Expand Up @@ -985,6 +991,12 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first)

ems.edit_with_params(params, endpoints, authentications)
end

it "stops the event monitor" do
expect(ems).to receive(:stop_event_monitor_queue)

ems.edit_with_params(params, endpoints, authentications)
end
end
end

Expand Down

0 comments on commit 0015fd8

Please sign in to comment.