From 8bd3eac92e0b098608b4b4f0becc9516d872213a Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 4 Jul 2018 12:06:25 +0100 Subject: Use database locking to prevent concurrent Terraform jobs Currently, the Terraform code uses chdir in the Ruby process to change to the right working directory. This affects all threads in the process, and thus means that all Terraform jobs conflict with each other. It would be good to fix this somehow, e.g. not changing directory, and just specifying the directory in which to run Terraform when starting it, but for now, use the advisory locks to force the jobs to run sequentially. --- app/models/backends/terraform_aws/backend_methods.rb | 2 +- app/models/backends/terraform_aws/mini_environment_methods.rb | 2 +- app/models/backends/terraform_libvirt/backend_methods.rb | 2 +- app/models/backends/terraform_libvirt/mini_environment_methods.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/backends/terraform_aws/backend_methods.rb b/app/models/backends/terraform_aws/backend_methods.rb index 5ade46c..ca2bd83 100644 --- a/app/models/backends/terraform_aws/backend_methods.rb +++ b/app/models/backends/terraform_aws/backend_methods.rb @@ -80,7 +80,7 @@ module Backends::TerraformAws::BackendMethods def within_backend_terraform_working_directory(&block) with_advisory_lock( - "aws_backend_terraform_working_directory/#{id}" + "terraform" ) do TerraformWorkingDirectory.new( terraform_state_id, diff --git a/app/models/backends/terraform_aws/mini_environment_methods.rb b/app/models/backends/terraform_aws/mini_environment_methods.rb index 36fd70d..d0a8ab5 100644 --- a/app/models/backends/terraform_aws/mini_environment_methods.rb +++ b/app/models/backends/terraform_aws/mini_environment_methods.rb @@ -82,7 +82,7 @@ module Backends::TerraformAws::MiniEnvironmentMethods def within_terraform_working_directory(mini_environment, &block) with_advisory_lock( - "aws_mini_environment_terraform_working_directory/#{mini_environment.id}" + "terraform" ) do TerraformWorkingDirectory.new( mini_environment_state_id(mini_environment), diff --git a/app/models/backends/terraform_libvirt/backend_methods.rb b/app/models/backends/terraform_libvirt/backend_methods.rb index 06b89e4..d14affa 100644 --- a/app/models/backends/terraform_libvirt/backend_methods.rb +++ b/app/models/backends/terraform_libvirt/backend_methods.rb @@ -56,7 +56,7 @@ module Backends::TerraformLibvirt::BackendMethods def within_backend_terraform_working_directory(&block) with_advisory_lock( - "libvirt_backend_terraform_working_directory/#{id}" + "terraform" ) do TerraformWorkingDirectory.new( terraform_state_id, diff --git a/app/models/backends/terraform_libvirt/mini_environment_methods.rb b/app/models/backends/terraform_libvirt/mini_environment_methods.rb index 9b68d49..ef2b4c1 100644 --- a/app/models/backends/terraform_libvirt/mini_environment_methods.rb +++ b/app/models/backends/terraform_libvirt/mini_environment_methods.rb @@ -79,7 +79,7 @@ module Backends::TerraformLibvirt::MiniEnvironmentMethods def within_terraform_working_directory(mini_environment, &block) with_advisory_lock( - "libvirt_mini_environment_terraform_working_directory/#{mini_environment.id}" + "terraform" ) do TerraformWorkingDirectory.new( mini_environment_state_id(mini_environment), -- cgit v1.2.3