Commit 5f90fd69 authored by Tiago Botelho's avatar Tiago Botelho

adds migration to remove sync time from remote mirrors

parent e3ef8f2b
......@@ -2,9 +2,6 @@ class RemoteMirror < ActiveRecord::Base
include AfterCommitQueue
include IgnorableColumn
BACKOFF_DELAY = 5
MAX_RETRIES = 5
attr_encrypted :credentials,
key: Gitlab::Application.secrets.db_key_base,
marshal: true,
......@@ -42,10 +39,6 @@ class RemoteMirror < ActiveRecord::Base
transition started: :failed
end
event :update_retry do
transition failed: :started
end
state :started
state :finished
state :failed
......
......@@ -100,7 +100,7 @@ class GitPushService < BaseService
def update_remote_mirrors
return if @project.remote_mirrors.empty?
@project.mark_remote_mirrors_as_failed!
@project.mark_stuck_remote_mirrors_as_failed!
@project.update_remote_mirrors
end
......
......@@ -74,6 +74,7 @@
= rm_form.label :enabled, "Remote mirror repository", class: "label-light append-bottom-0"
%p.light.append-bottom-0
Automatically update the remote mirror's branches, tags, and commits from this repository five minutes after every push.
In case of failure the mirroring will be retried 5 more times each adding a longer backoff period.
.form-group.has-feedback
= rm_form.label :url, "Git repository URL", class: "label-light"
= rm_form.text_field :url, class: "form-control", placeholder: 'https://username:password@gitlab.company.com/group/project.git'
......
......@@ -4,20 +4,19 @@ class RepositoryUpdateRemoteMirrorWorker
include Sidekiq::Worker
include Gitlab::ShellAdapter
sidekiq_options queue: :project_mirror, retry: RemoteMirror::MAX_RETRIES
BACKOFF_DELAY = 5.minutes.to_i
MAX_RETRIES = 5
sidekiq_retry_in do |count|
RemoteMirror::BACKOFF_DELAY**count
end
sidekiq_options queue: :project_mirror, retry: MAX_RETRIES
sidekiq_retry_in { |count| BACKOFF_DELAY**count }
def perform(remote_mirror_id, current_time)
begin
remote_mirror = RemoteMirror.find(remote_mirror_id)
last_update_at = remote_mirror.last_update_at
project = remote_mirror.project
current_user = project.creator
remote_mirror = RemoteMirror.find(remote_mirror_id)
return if remote_mirror&.last_update_at.to_i > current_time.to_i
return if last_update_at && last_update_at > current_time
project = remote_mirror.project
current_user = project.creator
result = Projects::UpdateRemoteMirrorService.new(project, current_user).execute(remote_mirror)
......
class RemoveSyncTimeColumnFromRemoteMirrors < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
remove_concurrent_index :remote_mirrors, [:sync_time] if index_exists? :remote_mirrors, [:sync_time]
remove_column :remote_mirrors, :sync_time, :integer
end
def down
add_column :remote_mirrors, :sync_time, :integer
add_concurrent_index :remote_mirrors, [:sync_time]
end
end
......@@ -1241,12 +1241,10 @@ ActiveRecord::Schema.define(version: 20170426175636) do
t.string "encrypted_credentials_salt"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "sync_time", default: 60, null: false
end
add_index "remote_mirrors", ["last_successful_update_at"], name: "index_remote_mirrors_on_last_successful_update_at", using: :btree
add_index "remote_mirrors", ["project_id"], name: "index_remote_mirrors_on_project_id", using: :btree
add_index "remote_mirrors", ["sync_time"], name: "index_remote_mirrors_on_sync_time", using: :btree
create_table "routes", force: :cascade do |t|
t.integer "source_id", null: false
......
......@@ -205,7 +205,7 @@ describe Project, models: true do
)
expect do
project.mark_as_failed_stuck_remote_mirrors('some message')
project.mark_stuck_remote_mirrors_as_failed!
end.to change { project.remote_mirrors.stuck.count }.from(1).to(0)
end
end
......
......@@ -25,13 +25,13 @@ describe GitPushService, services: true do
end
it 'fails stuck remote mirrors' do
expect(subject).to receive(:update_remote_mirrors)
expect(project).to receive(:mark_stuck_remote_mirrors_as_failed!)
subject.execute
end
it 'updates remote mirrors' do
expect(subject).to receive(:update_remote_mirrors)
expect(project).to receive(:update_remote_mirrors)
subject.execute
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