Add event store for Geo::CacheInvalidationEvent

parent df714a4e
# frozen_string_literal: true
module Geo
class CacheInvalidationEventStore < EventStore
self.event_type = :cache_invalidation_event
attr_reader :key
def initialize(key)
@key = key
end
private
def build_event
Geo::CacheInvalidationEvent.new(key: key)
end
# This is called by ProjectLogHelpers to build json log with context info
#
# @see ::Gitlab::Geo::ProjectLogHelpers
def base_log_data(message)
{
class: self.class.name,
cache_key: key.to_s,
job_id: get_sidekiq_job_id,
message: message
}.compact
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Geo::CacheInvalidationEventStore do
include EE::GeoHelpers
set(:secondary_node) { create(:geo_node) }
let(:cache_key) { 'cache-key' }
subject { described_class.new(cache_key) }
describe '#create' do
it_behaves_like 'a Geo event store', Geo::CacheInvalidationEvent
context 'when running on a primary node' do
before do
stub_primary_node
end
it 'tracks the cache key that should be invalidated' do
subject.create!
expect(Geo::CacheInvalidationEvent.last).to have_attributes(key: cache_key)
end
it 'logs an error message when event creation fail' do
subject = described_class.new(nil)
expected_message = {
class: described_class.name,
cache_key: '',
message: 'Cache invalidation event could not be created',
error: "Validation failed: Key can't be blank"
}
expect(Gitlab::Geo::Logger).to receive(:error)
.with(expected_message).and_call_original
subject.create!
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment