Skip to content
Snippets Groups Projects
Commit 103b5bf6 authored by Douwe Maan's avatar Douwe Maan
Browse files

Fix keys seed

parent e4eac1ff
No related branches found
No related tags found
No related merge requests found
module Sidekiq
module Worker
mattr_accessor :inside_after_commit
self.inside_after_commit = false
mattr_accessor :skip_transaction_check
self.skip_transaction_check = false
def self.skipping_transaction_check(&block)
skip_transaction_check = self.skip_transaction_check
self.skip_transaction_check = true
yield
ensure
self.skip_transaction_check = skip_transaction_check
end
 
module ClassMethods
module NoSchedulingFromTransactions
Loading
Loading
@@ -9,7 +17,7 @@ module Sidekiq
 
%i(perform_async perform_at perform_in).each do |name|
define_method(name) do |*args|
return super(*args) if Sidekiq::Worker.inside_after_commit
return super(*args) if Sidekiq::Worker.skip_transaction_check
return super(*args) unless ActiveRecord::Base.connection.open_transactions > NESTING
 
raise <<-MSG.strip_heredoc
Loading
Loading
@@ -30,16 +38,12 @@ end
 
module ActiveRecord
class Base
module InsideAfterCommit
module SkipTransactionCheckAfterCommit
def committed!(*)
inside_after_commit = Sidekiq::Worker.inside_after_commit
Sidekiq::Worker.inside_after_commit = true
super
ensure
Sidekiq::Worker.inside_after_commit = inside_after_commit
Sidekiq::Worker.skipping_transaction_check { super }
end
end
 
prepend InsideAfterCommit
prepend SkipTransactionCheckAfterCommit
end
end
require './spec/support/sidekiq'
 
# Creating keys runs a gitlab-shell worker. Since we may not have the right
# gitlab-shell path set (yet) we need to disable this for these fixtures.
Sidekiq::Testing.disable! do
Gitlab::Seeder.quiet do
# We want to run `add_to_shell` immediately instead of after the commit, so
# that it falls under `Sidekiq::Testing.disable!`.
Key.skip_callback(:commit, :after, :add_to_shell)
User.first(10).each do |user|
key = "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt#{user.id + 100}6k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
 
user.keys.create(
key = user.keys.create(
title: "Sample key #{user.id}",
key: key
)
 
Sidekiq::Worker.skipping_transaction_check do
key.add_to_shell
end
print '.'
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment