Merge pull request #1679 from okriuchykhin/ok_SCI_3177

Improve experiment preview image generation [SCI-3177]
This commit is contained in:
Alex Kriuchykhin 2019-04-17 20:35:29 +02:00 committed by GitHub
commit 8fa6bbc0ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 20 deletions

View file

@ -186,7 +186,7 @@ class CanvasController < ApplicationController
end
# Create workflow image
@experiment.delay.generate_workflow_img
@experiment.generate_workflow_img
flash[:success] = t('experiments.canvas.update.success_flash')
redirect_to canvas_experiment_path(@experiment)

View file

@ -237,10 +237,14 @@ class ExperimentsController < ApplicationController
end
def updated_img
if @experiment.workflowimg.present? && !@experiment.workflowimg.exists?
@experiment.workflowimg = nil
@experiment.save
@experiment.generate_workflow_img
end
respond_to do |format|
format.json do
if @experiment.workflowimg_updated_at.to_i >=
params[:timestamp].to_time.to_i
if @experiment.workflowimg.present?
render json: {}, status: 200
else
render json: {}, status: 404

View file

@ -49,8 +49,6 @@ class Experiment < ApplicationRecord
experiment.validates :archived_on, presence: true
end
after_touch { update_column(:workflowimg_updated_at, updated_at) }
scope :is_archived, ->(is_archived) { where("archived = ?", is_archived) }
def self.search(
@ -222,7 +220,11 @@ class Experiment < ApplicationRecord
end
def generate_workflow_img
Experiments::GenerateWorkflowImageService.call(experiment_id: id)
if workflowimg.present?
self.workflowimg = nil
save
end
Experiments::GenerateWorkflowImageService.delay.call(experiment_id: id)
end
# Get projects where user is either owner or user in the same team
@ -423,7 +425,7 @@ class Experiment < ApplicationRecord
# to other experiment
def generate_workflow_img_for_moved_modules(to_move)
Experiment.where(id: to_move.values.uniq).each do |exp|
exp.delay.generate_workflow_img
exp.generate_workflow_img
end
end

View file

@ -184,7 +184,7 @@ class MyModule < ApplicationRecord
raise ActiveRecord::Rollback
end
end
experiment.delay.generate_workflow_img
experiment.generate_workflow_img
restored
end

View file

@ -43,7 +43,7 @@ module Experiments
@errors.merge!(@c_exp.errors.to_hash) unless @c_exp.valid?
@c_exp = nil unless succeed?
@c_exp.delay.generate_workflow_img if succeed?
@c_exp.generate_workflow_img if succeed?
track_activity if succeed?
self

View file

@ -80,8 +80,6 @@ module Experiments
file.close
@exp.save
@exp.touch(:workflowimg_updated_at)
rescue StandardError => ex
logger.error ex.message
end
end
end

View file

@ -586,7 +586,7 @@ class TeamImporter
my_module_group.save!
@my_module_group_mappings[orig_module_group_id] = my_module_group.id
end
experiment.delay.generate_workflow_img
experiment.generate_workflow_img
create_my_modules(experiment_json['my_modules'], experiment, user_id)
experiment
end

View file

@ -1398,7 +1398,7 @@ module FirstTimeDataGenerator
)
# create thumbnail
experiment.delay.generate_workflow_img
experiment.generate_workflow_img
end
# Used for delayed jobs

View file

@ -29,10 +29,12 @@ describe TeamImporter do
PROJECT_ID = @project.id
USER_ID = @user.id
@team_importer = TeamImporter.new
@team_importer = TeamImporter.new
@exp = @team_importer.import_experiment_template_from_dir(TEMPLATE_DIR,
PROJECT_ID,
USER_ID)
Experiments::GenerateWorkflowImageService.call(experiment_id: @exp.id)
@exp.reload
end
describe 'Experiment variables' do
@ -51,12 +53,7 @@ describe TeamImporter do
it { expect(@exp.restored_by_id).to be_nil }
it { expect(@exp.restored_on).to be_nil }
it do
expect(@exp.workflowimg_updated_at).to eq(
'2019-01-21T13:31:04.682Z'.to_time
)
end
it { expect(@exp.workflowimg_file_size).to eq 4581 }
it { expect(@exp.workflowimg.exists?).to eq(true) }
end
describe 'Module groups' do