Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i121-script-to-move-records #834

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions app/jobs/process_files_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# app/jobs/process_files_job.rb
class ProcessFilesJob < ApplicationJob
queue_as :default

def perform(file_path)
puts "file_path=#{file_path}"
aprilrieger marked this conversation as resolved.
Show resolved Hide resolved
# Extract the directory where the file is located and the base name without .txt extension
dir_path = File.dirname(file_path)
puts "dir_path=#{dir_path}"
base_name = File.basename(file_path, '.txt')
puts "base_name=#{base_name}"

# Create a new directory named after the base name of the file
new_dir_path = File.join(dir_path, base_name)
puts "new_dir_path=#{new_dir_path}"
FileUtils.mkdir_p(new_dir_path) unless Dir.exist?(new_dir_path)

# Process the file lines as before
file_lines = File.readlines(file_path)

file_lines.each do |line|
filename = line.strip.sub(/^cpb-aacip-/, '') + '.xml'
# Correctly execute the find command and capture its output
puts "before find . -type f -name '#{filename}'"
find_command = "find . -type f -name '#{filename}'"
puts "after find . -type f -name '#{filename}'"
found_files = `#{find_command}`.split("\n")

# Adjust the destination_path to be the new directory
destination_path = File.join("./tmp/imports", base_name)
puts "destination_path=#{destination_path}"
FileUtils.mkdir_p(destination_path) unless Dir.exist?(destination_path)

found_files.each do |found_file_path|
if File.exist?(found_file_path)
FileUtils.mv(found_file_path, destination_path)
puts "Moved #{found_file_path} (found_file_path) to #{destination_path} (destination_path)"
end
end
end
end
end
Loading