Skip to content

Commit

Permalink
Rename method for updating settings timestamp in memcached
Browse files Browse the repository at this point in the history
This also removes an unnecessary intermediate method call
  • Loading branch information
carbonin committed Jan 30, 2020
1 parent 1da2f95 commit 1a57415
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
10 changes: 3 additions & 7 deletions app/models/miq_server/worker_management/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,16 @@ def sync_monitor
reset_queue_messages if roles_changed

@last_sync = Time.now.utc
update_sync_timestamp(@last_sync)
notify_workers_of_config_change(@last_sync)
end
end

def set_last_change(key, value)
key_store.set(key, value)
end

def key_store
require 'dalli'
@key_store ||= Dalli::Client.new(MiqMemcached.server_address, :namespace => "server_monitor")
end

def update_sync_timestamp(last_sync)
set_last_change("last_config_change", last_sync)
def notify_workers_of_config_change(last_sync)
key_store.set("last_config_change", last_sync)
end
end
2 changes: 1 addition & 1 deletion spec/models/miq_server/configuration_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
it "reloads the new changes into the settings for the resource" do
Vmdb::Settings.save!(miq_server, :some_test_setting => 2)
expect(Settings.some_test_setting).to be_nil
expect(miq_server).to receive(:update_sync_timestamp)
expect(miq_server).to receive(:notify_workers_of_config_change)

miq_server.reload_settings

Expand Down
7 changes: 4 additions & 3 deletions spec/models/miq_server/worker_monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,15 @@
end

context "for messaging through a key store" do
let(:key_store) { double("KeyStore") }
before do
allow(@miq_server).to receive(:key_store).and_return(@key_store)
allow(@miq_server).to receive(:key_store).and_return(key_store)
@ts = Time.now.utc
end

it "should update timestamp with config or role changes" do
expect(@miq_server).to receive(:set_last_change).with("last_config_change", @ts)
@miq_server.update_sync_timestamp(@ts)
expect(key_store).to receive(:set).with("last_config_change", @ts)
@miq_server.notify_workers_of_config_change(@ts)
end
end
end
Expand Down

0 comments on commit 1a57415

Please sign in to comment.