Merge pull request #1527 from okriuchykhin/ok_SCI_3101

Move templates project creation for new team to delayed job [SCI-3101]
This commit is contained in:
Alex Kriuchykhin 2019-03-01 13:55:49 +01:00 committed by GitHub
commit 985820a97c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View file

@ -315,7 +315,7 @@ class Team < ApplicationRecord
def generate_template_project
return if without_templates
TemplatesService.new.update_team(self)
TemplatesService.new.delay(queue: :templates).update_team(self)
end
include FirstTimeDataGenerator

View file

@ -32,13 +32,16 @@ class TemplatesService
return unless owner.present?
updated = false
exp_tmplt_dir_prefix = "#{@base_dir}/experiment_"
existing = tmpl_project.experiments.where.not(uuid: nil).pluck(:uuid)
@experiment_templates.except(*existing).each_value do |id|
importer_service = TeamImporter.new
importer_service.import_experiment_template_from_dir(
exp_tmplt_dir_prefix + id.to_s, tmpl_project.id, owner.id
)
updated = true
# Create lock in case another worker starts to update same team
tmpl_project.with_lock do
existing = tmpl_project.experiments.where.not(uuid: nil).pluck(:uuid)
@experiment_templates.except(*existing).each_value do |id|
importer_service = TeamImporter.new
importer_service.import_experiment_template_from_dir(
exp_tmplt_dir_prefix + id.to_s, tmpl_project.id, owner.id
)
updated = true
end
end
updated
end