diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-02-09 16:11:31 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-02-14 15:14:22 +0300 |
commit | 8aa1055fe3d24aa606f6a8d3c635f97b788e4e85 (patch) | |
tree | d15fe11aea1abc88ddfcd3aa4a153e09ae3c09c5 /db | |
parent | 1d8db6652f635d3f5326071b9dd00621b87e228b (diff) |
Use threads directly, introduce pool later:
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8987#note_22938402
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20170206040400_remove_inactive_default_email_services.rb | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb b/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb index 52e7f91bb01..f3863881229 100644 --- a/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb +++ b/db/post_migrate/20170206040400_remove_inactive_default_email_services.rb @@ -6,24 +6,52 @@ class RemoveInactiveDefaultEmailServices < ActiveRecord::Migration disable_ddl_transaction! def up - Gitlab::Database::ThreadedConnectionPool.with_pool(2) do |pool| - pool.execute_async <<-SQL.strip_heredoc + pool = create_connection_pool + threads = [] + + threads << Thread.new do + pool.with_connection do |connection| + connection.execute <<-SQL.strip_heredoc DELETE FROM services WHERE type = 'BuildsEmailService' AND active IS FALSE AND properties = '{"notify_only_broken_builds":true}'; - SQL + SQL + end + end - pool.execute_async <<-SQL.strip_heredoc + threads << Thread.new do + pool.with_connection do |connection| + connection.execute <<-SQL.strip_heredoc DELETE FROM services WHERE type = 'PipelinesEmailService' AND active IS FALSE AND properties = '{"notify_only_broken_pipelines":true}'; - SQL + SQL + end end + + threads.each(&:join) end def down # Nothing can be done to restore the records end + + private + + def create_connection_pool + # See activerecord-4.2.7.1/lib/active_record/connection_adapters/connection_specification.rb + env = Rails.env + original_config = ActiveRecord::Base.configurations + env_config = original_config[env].merge('pool' => 2) + config = original_config.merge(env => env_config) + + spec = + ActiveRecord:: + ConnectionAdapters:: + ConnectionSpecification::Resolver.new(config).spec(env.to_sym) + + ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec) + end end |