Commit 72f73b42 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'dm-project-factory-import-state-ee' into 'master'

[EE] Fix project factory `import_*` traits

See merge request gitlab-org/gitlab-ee!5599
parents 783cfb9e d361aa71
......@@ -672,8 +672,8 @@ class Project < ActiveRecord::Base
}
end
def ensure_import_state
return if self[:import_status] == 'none' || self[:import_status].nil?
def ensure_import_state(force: false)
return if !force && (self[:import_status] == 'none' || self[:import_status].nil?)
return unless import_state.nil?
create_import_state(import_state_args)
......@@ -682,39 +682,39 @@ class Project < ActiveRecord::Base
end
def import_schedule
ensure_import_state
ensure_import_state(force: true)
import_state&.schedule
import_state.schedule
end
def force_import_start
ensure_import_state
ensure_import_state(force: true)
import_state&.force_start
import_state.force_start
end
def import_start
ensure_import_state
ensure_import_state(force: true)
import_state&.start
import_state.start
end
def import_fail
ensure_import_state
ensure_import_state(force: true)
import_state&.fail_op
import_state.fail_op
end
def import_finish
ensure_import_state
ensure_import_state(force: true)
import_state&.finish
import_state.finish
end
def import_jid=(new_jid)
ensure_import_state
ensure_import_state(force: true)
import_state&.jid = new_jid
import_state.jid = new_jid
end
def import_jid
......@@ -724,9 +724,9 @@ class Project < ActiveRecord::Base
end
def import_error=(new_error)
ensure_import_state
ensure_import_state(force: true)
import_state&.last_error = new_error
import_state.last_error = new_error
end
def import_error
......@@ -736,9 +736,9 @@ class Project < ActiveRecord::Base
end
def import_status=(new_status)
ensure_import_state
ensure_import_state(force: true)
import_state&.status = new_status
import_state.status = new_status
end
def import_status
......
......@@ -69,78 +69,44 @@ FactoryBot.define do
end
trait :import_none do
transient do
status :none
end
before(:create) do |project, evaluator|
project.create_import_state(:status, evaluator.status)
end
import_status :none
end
trait :import_scheduled do
transient do
status :scheduled
last_update_scheduled_at Time.now
end
import_status :scheduled
before(:create) do |project, evaluator|
project.create_import_state(status: evaluator.status,
last_update_scheduled_at: evaluator.last_update_scheduled_at)
after(:create) do |project, _|
project.import_state&.update_attributes(last_update_scheduled_at: Time.now)
end
end
trait :import_started do
transient do
status :started
last_update_started_at Time.now
end
import_status :started
before(:create) do |project, evaluator|
project.create_import_state(status: evaluator.status,
last_update_started_at: evaluator.last_update_started_at)
after(:create) do |project, _|
project.import_state&.update_attributes(last_update_started_at: Time.now)
end
end
trait :import_finished do
transient do
timestamp = Time.now
timestamp = Time.now
status :finished
last_update_at timestamp
last_successful_update_at timestamp
end
before(:create) do |project, evaluator|
project.create_import_state(status: evaluator.status,
last_update_at: evaluator.last_update_at,
last_successful_update_at: evaluator.last_successful_update_at)
end
import_status :finished
mirror_last_update_at timestamp
mirror_last_successful_update_at timestamp
end
trait :import_failed do
transient do
status :failed
last_update_at { Time.now }
end
before(:create) do |project, evaluator|
project.create_import_state(status: evaluator.status,
last_update_at: evaluator.last_update_at)
end
import_status :failed
mirror_last_update_at { Time.now }
end
trait :import_hard_failed do
transient do
status :failed
retry_count Gitlab::Mirror::MAX_RETRY + 1
last_update_at Time.now - 1.minute
end
import_status :failed
mirror_last_update_at { Time.now - 1.minute }
before(:create) do |project, evaluator|
project.create_import_state(status: evaluator.status,
retry_count: evaluator.retry_count,
last_update_at: evaluator.last_update_at)
after(:create) do |project|
project.import_state&.update_attributes(retry_count: Gitlab::Mirror::MAX_RETRY + 1)
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