BigW Consortium Gitlab

Update commit status from external CI services less aggressively

parent 0eb74426
......@@ -60,13 +60,16 @@ module ReactiveCaching
end
def with_reactive_cache(*args, &blk)
within_reactive_cache_lifetime(*args) do
bootstrap = !within_reactive_cache_lifetime?(*args)
Rails.cache.write(alive_reactive_cache_key(*args), true, expires_in: self.class.reactive_cache_lifetime)
if bootstrap
ReactiveCachingWorker.perform_async(self.class, id, *args)
nil
else
data = Rails.cache.read(full_reactive_cache_key(*args))
yield data if data.present?
end
ensure
Rails.cache.write(alive_reactive_cache_key(*args), true, expires_in: self.class.reactive_cache_lifetime)
ReactiveCachingWorker.perform_async(self.class, id, *args)
end
def clear_reactive_cache!(*args)
......@@ -75,7 +78,7 @@ module ReactiveCaching
def exclusively_update_reactive_cache!(*args)
locking_reactive_cache(*args) do
within_reactive_cache_lifetime(*args) do
if within_reactive_cache_lifetime?(*args)
enqueuing_update(*args) do
value = calculate_reactive_cache(*args)
Rails.cache.write(full_reactive_cache_key(*args), value)
......@@ -105,8 +108,8 @@ module ReactiveCaching
Gitlab::ExclusiveLease.cancel(full_reactive_cache_key(*args), uuid)
end
def within_reactive_cache_lifetime(*args)
yield if Rails.cache.read(alive_reactive_cache_key(*args))
def within_reactive_cache_lifetime?(*args)
!!Rails.cache.read(alive_reactive_cache_key(*args))
end
def enqueuing_update(*args)
......
---
title: Update commit status from external CI services less aggressively
merge_request: 18802
author:
type: fixed
......@@ -29,12 +29,6 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
end
end
let(:now) { Time.now.utc }
around do |example|
Timecop.freeze(now) { example.run }
end
let(:calculation) { -> { 2 + 2 } }
let(:cache_key) { "foo:666" }
let(:instance) { CacheTest.new(666, &calculation) }
......@@ -49,13 +43,15 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
context 'when cache is empty' do
it { is_expected.to be_nil }
it 'queues a background worker' do
it 'enqueues a background worker to bootstrap the cache' do
expect(ReactiveCachingWorker).to receive(:perform_async).with(CacheTest, 666)
go!
end
it 'updates the cache lifespan' do
expect(reactive_cache_alive?(instance)).to be_falsy
go!
expect(reactive_cache_alive?(instance)).to be_truthy
......@@ -69,6 +65,18 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
it { is_expected.to eq(2) }
it 'does not enqueue a background worker' do
expect(ReactiveCachingWorker).not_to receive(:perform_async)
go!
end
it 'updates the cache lifespan' do
expect(Rails.cache).to receive(:write).with(alive_reactive_cache_key(instance), true, expires_in: anything)
go!
end
context 'and expired' do
before do
invalidate_reactive_cache(instance)
......
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