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 ...@@ -2,9 +2,6 @@ class RemoteMirror < ActiveRecord::Base
include AfterCommitQueue include AfterCommitQueue
include IgnorableColumn include IgnorableColumn
BACKOFF_DELAY = 5
MAX_RETRIES = 5
attr_encrypted :credentials, attr_encrypted :credentials,
key: Gitlab::Application.secrets.db_key_base, key: Gitlab::Application.secrets.db_key_base,
marshal: true, marshal: true,
...@@ -42,10 +39,6 @@ class RemoteMirror < ActiveRecord::Base ...@@ -42,10 +39,6 @@ class RemoteMirror < ActiveRecord::Base
transition started: :failed transition started: :failed
end end
event :update_retry do
transition failed: :started
end
state :started state :started
state :finished state :finished
state :failed state :failed
......
...@@ -100,7 +100,7 @@ class GitPushService < BaseService ...@@ -100,7 +100,7 @@ class GitPushService < BaseService
def update_remote_mirrors def update_remote_mirrors
return if @project.remote_mirrors.empty? return if @project.remote_mirrors.empty?
@project.mark_remote_mirrors_as_failed! @project.mark_stuck_remote_mirrors_as_failed!
@project.update_remote_mirrors @project.update_remote_mirrors
end end
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
= rm_form.label :enabled, "Remote mirror repository", class: "label-light append-bottom-0" = rm_form.label :enabled, "Remote mirror repository", class: "label-light append-bottom-0"
%p.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. 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 .form-group.has-feedback
= rm_form.label :url, "Git repository URL", class: "label-light" = 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' = rm_form.text_field :url, class: "form-control", placeholder: 'https://username:password@gitlab.company.com/group/project.git'
......
...@@ -4,21 +4,20 @@ class RepositoryUpdateRemoteMirrorWorker ...@@ -4,21 +4,20 @@ class RepositoryUpdateRemoteMirrorWorker
include Sidekiq::Worker include Sidekiq::Worker
include Gitlab::ShellAdapter 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| sidekiq_options queue: :project_mirror, retry: MAX_RETRIES
RemoteMirror::BACKOFF_DELAY**count sidekiq_retry_in { |count| BACKOFF_DELAY**count }
end
def perform(remote_mirror_id, current_time) def perform(remote_mirror_id, current_time)
begin begin
remote_mirror = RemoteMirror.find(remote_mirror_id) remote_mirror = RemoteMirror.find(remote_mirror_id)
last_update_at = remote_mirror.last_update_at return if remote_mirror&.last_update_at.to_i > current_time.to_i
project = remote_mirror.project project = remote_mirror.project
current_user = project.creator current_user = project.creator
return if last_update_at && last_update_at > current_time
result = Projects::UpdateRemoteMirrorService.new(project, current_user).execute(remote_mirror) result = Projects::UpdateRemoteMirrorService.new(project, current_user).execute(remote_mirror)
if result[:status] == :error if result[:status] == :error
......
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 ...@@ -1241,12 +1241,10 @@ ActiveRecord::Schema.define(version: 20170426175636) do
t.string "encrypted_credentials_salt" t.string "encrypted_credentials_salt"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "sync_time", default: 60, null: false
end end
add_index "remote_mirrors", ["last_successful_update_at"], name: "index_remote_mirrors_on_last_successful_update_at", using: :btree 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", ["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| create_table "routes", force: :cascade do |t|
t.integer "source_id", null: false t.integer "source_id", null: false
......
...@@ -205,7 +205,7 @@ describe Project, models: true do ...@@ -205,7 +205,7 @@ describe Project, models: true do
) )
expect 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.to change { project.remote_mirrors.stuck.count }.from(1).to(0)
end end
end end
......
...@@ -25,13 +25,13 @@ describe GitPushService, services: true do ...@@ -25,13 +25,13 @@ describe GitPushService, services: true do
end end
it 'fails stuck remote mirrors' do 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 subject.execute
end end
it 'updates remote mirrors' do it 'updates remote mirrors' do
expect(subject).to receive(:update_remote_mirrors) expect(project).to receive(:update_remote_mirrors)
subject.execute subject.execute
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