Commit 0f317484 authored by Michael Kozono's avatar Michael Kozono

Merge branch '206946-fix-job-artifact-registry-insert-for-model-ids' into 'master'

Geo - Set success to false in Geo::JobArtifactRegistry.insert_for_model_ids

See merge request gitlab-org/gitlab!29553
parents 71c834ef c73125b1
......@@ -76,7 +76,8 @@ module Geo
# @param [Array<Integer>] except_ids ids that will be ignored from the query
# rubocop:disable CodeReuse/ActiveRecord
def find_never_synced_registries(batch_size:, except_ids: [])
Geo::LfsObjectRegistry.never
Geo::LfsObjectRegistry
.never
.model_id_not_in(except_ids)
.limit(batch_size)
end
......
......@@ -31,6 +31,16 @@ class Geo::JobArtifactRegistry < Geo::BaseRegistry
false
end
# TODO: remove once `success` column has a default value set
# https://gitlab.com/gitlab-org/gitlab/-/issues/214407
def self.insert_for_model_ids(ids)
records = ids.map do |id|
new(artifact_id: id, success: false, created_at: Time.zone.now)
end
bulk_insert!(records, returns: :ids)
end
def self.replication_enabled?
JobArtifactUploader.object_store_enabled? ? Gitlab::Geo.current_node.sync_object_storage? : true
end
......
......@@ -10,6 +10,20 @@ describe Geo::JobArtifactRegistry, :geo do
let(:invalid_items_for_bulk_insertion) { [] } # class does not have any validations defined
end
describe '.insert_for_model_ids' do
it 'returns an array with the primary key values for all inserted records' do
ids = described_class.insert_for_model_ids([1])
expect(ids).to contain_exactly(a_kind_of(Integer))
end
it 'defaults success column to false for all inserted records' do
ids = described_class.insert_for_model_ids([1])
expect(described_class.where(id: ids).pluck(:success)).to eq([false])
end
end
describe '.replication_enabled?' do
context 'when Object Storage is enabled' do
before do
......
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