From 45f66c8021704276cb5ddf8831606ced71e955e9 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 2 May 2017 07:50:52 +0000 Subject: [PATCH 1/4] Make auto-cancelling pending pipelines on by default --- .../enable-auto-cancelling-by-default.yml | 4 ++++ ..._auto_cancel_pending_pipelines_on_by_default.rb | 13 +++++++++++++ ...enable_auto_cancel_pending_pipelines_for_all.rb | 14 ++++++++++++++ db/schema.rb | 2 +- 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/enable-auto-cancelling-by-default.yml create mode 100644 db/migrate/20170502065653_make_auto_cancel_pending_pipelines_on_by_default.rb create mode 100644 db/migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb diff --git a/changelogs/unreleased/enable-auto-cancelling-by-default.yml b/changelogs/unreleased/enable-auto-cancelling-by-default.yml new file mode 100644 index 00000000000..8b1659bf38b --- /dev/null +++ b/changelogs/unreleased/enable-auto-cancelling-by-default.yml @@ -0,0 +1,4 @@ +--- +title: Enable cancelling non-HEAD pending pipelines by default for all projects +merge_request: 11023 +author: diff --git a/db/migrate/20170502065653_make_auto_cancel_pending_pipelines_on_by_default.rb b/db/migrate/20170502065653_make_auto_cancel_pending_pipelines_on_by_default.rb new file mode 100644 index 00000000000..03bf626a08a --- /dev/null +++ b/db/migrate/20170502065653_make_auto_cancel_pending_pipelines_on_by_default.rb @@ -0,0 +1,13 @@ +class MakeAutoCancelPendingPipelinesOnByDefault < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + change_column_default(:projects, :auto_cancel_pending_pipelines, 1) + end + + def down + change_column_default(:projects, :auto_cancel_pending_pipelines, 0) + end +end diff --git a/db/migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb b/db/migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb new file mode 100644 index 00000000000..bc43cd34c4d --- /dev/null +++ b/db/migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb @@ -0,0 +1,14 @@ +class EnableAutoCancelPendingPipelinesForAll < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + def up + connection.execute( + 'UPDATE projects SET auto_cancel_pending_pipelines = 1') + end + + def down + # Nothing we can do! + end +end diff --git a/db/schema.rb b/db/schema.rb index 65eaccf766a..e164347a054 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -986,7 +986,7 @@ ActiveRecord::Schema.define(version: 20170508190732) do t.text "description_html" t.boolean "only_allow_merge_if_all_discussions_are_resolved" t.boolean "printing_merge_request_link_enabled", default: true, null: false - t.integer "auto_cancel_pending_pipelines", default: 0, null: false + t.integer "auto_cancel_pending_pipelines", default: 1, null: false t.string "import_jid" t.integer "cached_markdown_version" t.datetime "last_repository_updated_at" From dbd034b7a20c5b8f25df253d9be82c986346dc5a Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 2 May 2017 21:27:24 +0800 Subject: [PATCH 2/4] Disable auto_cancel_pending_pipelines in PostReceive test --- spec/workers/post_receive_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb index 3289c2df1fb..f4bc63bcc6a 100644 --- a/spec/workers/post_receive_spec.rb +++ b/spec/workers/post_receive_spec.rb @@ -4,13 +4,16 @@ describe PostReceive do let(:changes) { "123456 789012 refs/heads/tést\n654321 210987 refs/tags/tag" } let(:wrongly_encoded_changes) { changes.encode("ISO-8859-1").force_encoding("UTF-8") } let(:base64_changes) { Base64.encode64(wrongly_encoded_changes) } - let(:project) { create(:project, :repository) } let(:project_identifier) { "project-#{project.id}" } let(:key) { create(:key, user: project.owner) } let(:key_id) { key.shell_id } + let(:project) do + create(:project, :repository, auto_cancel_pending_pipelines: 'disabled') + end + context "as a sidekiq worker" do - it "reponds to #perform" do + it "responds to #perform" do expect(described_class.new).to respond_to(:perform) end end From b5bffbd4adc5005b8c9f7d82d68a01743fbf2f28 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 15 May 2017 14:27:30 +0800 Subject: [PATCH 3/4] Move to post_migrate and use update_column_in_batches --- ...70502070007_enable_auto_cancel_pending_pipelines_for_all.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename db/{migrate => post_migrate}/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb (69%) diff --git a/db/migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb b/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb similarity index 69% rename from db/migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb rename to db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb index bc43cd34c4d..0abc75a3ed6 100644 --- a/db/migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb +++ b/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb @@ -4,8 +4,7 @@ class EnableAutoCancelPendingPipelinesForAll < ActiveRecord::Migration DOWNTIME = false def up - connection.execute( - 'UPDATE projects SET auto_cancel_pending_pipelines = 1') + update_column_in_batches(:projects, :auto_cancel_pending_pipelines, 1) end def down From 20ece0aac37ab38c6207bd3d0a4c6276275fb049 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 15 May 2017 16:22:29 +0800 Subject: [PATCH 4/4] Disable transaction for updating the table --- ...170502070007_enable_auto_cancel_pending_pipelines_for_all.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb b/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb index 0abc75a3ed6..a19b73fc114 100644 --- a/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb +++ b/db/post_migrate/20170502070007_enable_auto_cancel_pending_pipelines_for_all.rb @@ -1,6 +1,8 @@ class EnableAutoCancelPendingPipelinesForAll < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers + disable_ddl_transaction! + DOWNTIME = false def up