Improve experiment preview image generation [SCI-3177]

This commit is contained in:
Oleksii Kriuchykhin 2019-04-17 12:06:46 +02:00
parent 782d1dfc2d
commit f9832013b0
8 changed files with 17 additions and 13 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

@ -565,7 +565,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