Skip to content

Commit

Permalink
Merge pull request #159 from ninoseki/hotfix-connection-pool-issue
Browse files Browse the repository at this point in the history
Hotfix connection pool issue
  • Loading branch information
ninoseki authored Aug 29, 2021
2 parents ae9d0f2 + 126e9f8 commit 1f12739
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions lib/miteru/downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ def download_kits(kits)

def download_kit(kit)
destination = kit.filepath_to_download

begin
downloaded_as = HTTPClient.download(kit.url, destination)
hash = sha256(downloaded_as)
rescue Down::Error => e
puts "Failed to download: #{kit.url} (#{e})"
return
end

hash = sha256(downloaded_as)

ActiveRecord::Base.connection_pool.with_connection do
# Remove a downloaded file if it is not unique
if duplicated?(hash)
unless Record.unique_hash?(hash)
puts "Don't download #{kit.url}. The same hash is already recorded. (SHA256: #{hash})."
FileUtils.rm downloaded_as
return
Expand All @@ -36,8 +43,6 @@ def download_kit(kit)
# Record a kit in DB
Record.create_by_kit_and_hash(kit, hash)
puts "Download #{kit.url} as #{downloaded_as}"
rescue Down::Error => e
puts "Failed to download: #{kit.url} (#{e})"
end
end

Expand All @@ -49,9 +54,5 @@ def sha256(path)
memo[path] = hash
hash
end

def duplicated?(hash)
!Record.unique_hash?(hash)
end
end
end
2 changes: 1 addition & 1 deletion lib/miteru/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Miteru
VERSION = "1.0.0"
VERSION = "1.0.1"
end

0 comments on commit 1f12739

Please sign in to comment.