Remove docx preview processing flag [SCI-5601]

This commit is contained in:
aignatov-bio 2021-06-09 10:58:27 +02:00
parent 2be59bf8b2
commit 16f83a3e60
6 changed files with 6 additions and 29 deletions

View file

@ -52,7 +52,7 @@ module Reports
team_name: sanitize_input(report.team.name))
)
Reports::DocxPreviewJob.perform_later(report.id)
Reports::DocxPreviewJob.perform_now(report.id)
notification.create_user_notification(user)
ensure
file.close

View file

@ -7,9 +7,6 @@ module Reports
discard_on StandardError do |job, error|
report = Report.find_by(id: job.arguments.first)
ActiveRecord::Base.no_touching do
report&.update(docx_preview_processing: false)
end
Rails.logger.error("Couldn't generate PDF preview for DOCX Report with id: #{job.arguments.first}. Error:\n #{error}")
end
@ -34,7 +31,6 @@ module Reports
ActiveRecord::Base.no_touching do
report.docx_preview_file.attach(io: File.open(preview_file), filename: "#{blob.filename.base}.pdf")
report.update(docx_preview_processing: false)
end
Rails.logger.info("Finished preparing PDF preview for file #{blob.filename.sanitized}.")
end

View file

@ -97,16 +97,6 @@ class Report < ApplicationRecord
report_elements.order(:position).select { |el| el.parent.blank? }
end
def docx_preview_ready?
return false if docx_preview_processing
return true if docx_preview_file.attached?
Reports::DocxPreviewJob.perform_later(id)
ActiveRecord::Base.no_touching { update(docx_preview_processing: true) }
false
end
# Clean report elements from report
# the function runs before the report is edit
def cleanup_report

View file

@ -11,7 +11,7 @@
<div class="file-preview-container">
<% if report_type == 'pdf' %>
<%= render partial: 'shared/pdf_viewer.html.erb', locals: { asset: report.pdf_file, report_document: true } %>
<% elsif report_type == 'docx' && report.docx_preview_ready? %>
<% elsif report_type == 'docx' %>
<%= render partial: 'shared/pdf_viewer.html.erb', locals: { asset: report.docx_preview_file, report_document: true } %>
<% else %>
<div>

View file

@ -1,7 +0,0 @@
# frozen_string_literal: true
class AddDocxPreviewProcessingToReports < ActiveRecord::Migration[6.1]
def change
add_column :reports, :docx_preview_processing, :boolean, default: false, null: false
end
end

View file

@ -1307,10 +1307,9 @@ CREATE TABLE public.reports (
updated_at timestamp without time zone NOT NULL,
last_modified_by_id bigint,
team_id bigint,
pdf_file_status integer,
docx_file_status integer,
settings jsonb DEFAULT '{}'::jsonb NOT NULL,
docx_preview_processing boolean DEFAULT false NOT NULL
pdf_file_status integer DEFAULT 0,
docx_file_status integer DEFAULT 0,
settings jsonb DEFAULT '{}'::jsonb NOT NULL
);
@ -7236,7 +7235,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210325152257'),
('20210407143303'),
('20210410100006'),
('20210506125657'),
('20210525143303');
('20210506125657');