diff --git a/app/controllers/canvas_controller.rb b/app/controllers/canvas_controller.rb index 05ebfe730..ede012a2e 100644 --- a/app/controllers/canvas_controller.rb +++ b/app/controllers/canvas_controller.rb @@ -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) diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index cffd51cf4..ad77bf398 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -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 diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 2ee527e66..d730b06d7 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -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 diff --git a/app/models/my_module.rb b/app/models/my_module.rb index f8d726537..914c018fd 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -184,7 +184,7 @@ class MyModule < ApplicationRecord raise ActiveRecord::Rollback end end - experiment.delay.generate_workflow_img + experiment.generate_workflow_img restored end diff --git a/app/services/experiments/copy_experiment_as_template_service.rb b/app/services/experiments/copy_experiment_as_template_service.rb index c49e28e12..5a708ce7b 100644 --- a/app/services/experiments/copy_experiment_as_template_service.rb +++ b/app/services/experiments/copy_experiment_as_template_service.rb @@ -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 diff --git a/app/services/experiments/generate_workflow_image_service.rb b/app/services/experiments/generate_workflow_image_service.rb index 71ca146dc..725f67be8 100644 --- a/app/services/experiments/generate_workflow_image_service.rb +++ b/app/services/experiments/generate_workflow_image_service.rb @@ -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 diff --git a/app/services/team_importer.rb b/app/services/team_importer.rb index 1fa055d76..b140f23d6 100644 --- a/app/services/team_importer.rb +++ b/app/services/team_importer.rb @@ -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 diff --git a/app/utilities/first_time_data_generator.rb b/app/utilities/first_time_data_generator.rb index e2a08b316..40db93395 100644 --- a/app/utilities/first_time_data_generator.rb +++ b/app/utilities/first_time_data_generator.rb @@ -1398,7 +1398,7 @@ module FirstTimeDataGenerator ) # create thumbnail - experiment.delay.generate_workflow_img + experiment.generate_workflow_img end # Used for delayed jobs diff --git a/spec/services/model_importers/team_importer_spec.rb b/spec/services/model_importers/team_importer_spec.rb index 4ca8e32ae..9a748cb4a 100644 --- a/spec/services/model_importers/team_importer_spec.rb +++ b/spec/services/model_importers/team_importer_spec.rb @@ -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