Skip to content

Commit

Permalink
FIX: Do not change directory when decompressing S3 inventory
Browse files Browse the repository at this point in the history
In sidekiq, jobs are run in multiple threads within the same process. `cd` affects the entire process, so can cause unexpected issues in other running jobs.
  • Loading branch information
davidtaylorhq committed Jun 13, 2019
1 parent 66b15b9 commit ed21128
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/discourse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class SidekiqExceptionHandler
end

class Utils
def self.execute_command(*command, failure_message: "", success_status_codes: [0])
stdout, stderr, status = Open3.capture3(*command)
def self.execute_command(*command, failure_message: "", success_status_codes: [0], chdir: ".")
stdout, stderr, status = Open3.capture3(*command, chdir: chdir)

if !status.exited? || !success_status_codes.include?(status.exitstatus)
failure_message = "#{failure_message}\n" if !failure_message.blank?
Expand Down
8 changes: 3 additions & 5 deletions lib/s3_inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,9 @@ def download_inventory_files_to_tmp_directory
end

def decompress_inventory_files
FileUtils.cd(tmp_directory) do
files.each do |file|
log "Decompressing inventory file '#{file[:filename]}', this may take a while..."
Discourse::Utils.execute_command('gzip', '--decompress', file[:filename], failure_message: "Failed to decompress inventory file '#{file[:filename]}'.")
end
files.each do |file|
log "Decompressing inventory file '#{file[:filename]}', this may take a while..."
Discourse::Utils.execute_command('gzip', '--decompress', file[:filename], failure_message: "Failed to decompress inventory file '#{file[:filename]}'.", chdir: tmp_directory)
end
end

Expand Down

0 comments on commit ed21128

Please sign in to comment.