Commit 34febd35 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Simplify Ci::BuildTraceChunk.persistable_store

Before this change, Ci::BuildTraceChunk.persistable_store was
implemented by scanning an array with 3 values: [false, true,
BuildTraceChunks::Fog.new.available?]. What could be a single if-else
("if Fog is available, then X, else, Y") was presented as a loop.

This commit replaces the loop with a single if-else.
parent 33d2c0b6
......@@ -25,8 +25,6 @@ module Ci
FailedToPersistDataError = Class.new(StandardError)
# Note: The ordering of this hash is related to the precedence of persist store.
# The bottom item takes the highest precedence, and the top item takes the lowest precedence.
DATA_STORES = {
redis: 1,
database: 2,
......@@ -48,8 +46,7 @@ module Ci
end
def persistable_store
# get first available store from the back of the list
all_stores.reverse.find { |store| get_store_class(store).available? }
STORE_TYPES[:fog].available? ? :fog : :database
end
def get_store_class(store)
......
......@@ -3,10 +3,6 @@
module Ci
module BuildTraceChunks
class Database
def available?
true
end
def keys(relation)
[]
end
......
......@@ -3,10 +3,18 @@
module Ci
module BuildTraceChunks
class Fog
def available?
def self.available?
object_store.enabled
end
def self.object_store
Gitlab.config.artifacts.object_store
end
def available?
self.class.available?
end
def data(model)
files.get(key(model))&.body
rescue Excon::Error::NotFound
......@@ -85,7 +93,7 @@ module Ci
end
def object_store
Gitlab.config.artifacts.object_store
self.class.object_store
end
def object_store_raw_config
......
......@@ -31,10 +31,6 @@ module Ci
end
EOS
def available?
true
end
def data(model)
Gitlab::Redis::SharedState.with do |redis|
redis.get(key(model))
......
......@@ -5,12 +5,6 @@ require 'spec_helper'
RSpec.describe Ci::BuildTraceChunks::Database do
let(:data_store) { described_class.new }
describe '#available?' do
subject { data_store.available? }
it { is_expected.to be_truthy }
end
describe '#data' do
subject { data_store.data(model) }
......
......@@ -5,12 +5,6 @@ require 'spec_helper'
RSpec.describe Ci::BuildTraceChunks::Redis, :clean_gitlab_redis_shared_state do
let(:data_store) { described_class.new }
describe '#available?' do
subject { data_store.available? }
it { is_expected.to be_truthy }
end
describe '#data' do
subject { data_store.data(model) }
......
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