From a53a9980c56556b3e65321ac8e0ca455ea9f2ce6 Mon Sep 17 00:00:00 2001 From: Andrew Cain Date: Thu, 21 Mar 2024 14:39:57 +1100 Subject: [PATCH] feat: delay generation for a short period to allow sidekiq to handle --- app/helpers/file_helper.rb | 10 +++++++--- app/models/portfolio_evidence.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/helpers/file_helper.rb b/app/helpers/file_helper.rb index 54b263b2a..7523f7eb4 100644 --- a/app/helpers/file_helper.rb +++ b/app/helpers/file_helper.rb @@ -305,14 +305,18 @@ def qpdf(path) # # Move files between stages - new -> in process -> done - # - def move_files(from_path, to_path, retain_from = false) + # Params: + # - from path = copy from + # - to path = destination + # - retain_from = true if you want to keep from, otherwise it is deleted + # - only_before = date for files to move (only if retain from is true) + def move_files(from_path, to_path, retain_from = false, only_before = nil) # move into the new dir - and mv files to the in_process_dir pwd = FileUtils.pwd begin FileUtils.mkdir_p(to_path) Dir.chdir(from_path) - FileUtils.mv Dir.glob('*'), to_path, force: true + FileUtils.mv Dir.glob('*').filter{|fn| !retain_from || only_before.nil? || File.ctime(fn) < only_before}, to_path, force: true Dir.chdir(to_path) begin # remove from_path as files are now "in process" diff --git a/app/models/portfolio_evidence.rb b/app/models/portfolio_evidence.rb index 66179158b..5e0790593 100644 --- a/app/models/portfolio_evidence.rb +++ b/app/models/portfolio_evidence.rb @@ -22,7 +22,7 @@ def self.move_to_pid_folder pid_folder = File.join(student_work_dir(:in_process), "pid_#{Process.pid}") # Move everything in "new" to "pid" folder but retain the old "new" folder - FileHelper.move_files(student_work_dir(:new), pid_folder, true) + FileHelper.move_files(student_work_dir(:new), pid_folder, true, DateTime.now - 1.minute) pid_folder end