mirror of
https://github.com/discourse/discourse.git
synced 2024-12-20 16:13:42 +08:00
DEV: Use a Logger
for s3:upload_assets
(#30218)
Now that we run the `upload` method in different threads, we need to
synchronize writes to `STDOUT` which we can do so by using a `Logger`.
Follow-up to 49e8353959
This commit is contained in:
parent
49e8353959
commit
9a2e31b9af
|
@ -24,7 +24,7 @@ def should_skip?(path)
|
||||||
existing_assets.include?(prefix_s3_path(path))
|
existing_assets.include?(prefix_s3_path(path))
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(path, remote_path, content_type, content_encoding = nil)
|
def upload(path, remote_path, content_type, content_encoding = nil, logger:)
|
||||||
options = {
|
options = {
|
||||||
cache_control: "max-age=31556952, public, immutable",
|
cache_control: "max-age=31556952, public, immutable",
|
||||||
content_type: content_type,
|
content_type: content_type,
|
||||||
|
@ -34,9 +34,9 @@ def upload(path, remote_path, content_type, content_encoding = nil)
|
||||||
options[:content_encoding] = content_encoding if content_encoding
|
options[:content_encoding] = content_encoding if content_encoding
|
||||||
|
|
||||||
if should_skip?(remote_path)
|
if should_skip?(remote_path)
|
||||||
puts "Skipping: #{remote_path}"
|
logger << "Skipping: #{remote_path}"
|
||||||
else
|
else
|
||||||
puts "Uploading: #{remote_path}"
|
logger << "Uploading: #{remote_path}"
|
||||||
|
|
||||||
File.open(path) { |file| helper.upload(file, remote_path, options) }
|
File.open(path) { |file| helper.upload(file, remote_path, options) }
|
||||||
end
|
end
|
||||||
|
@ -200,7 +200,8 @@ task "s3:upload_assets" => [:environment, "s3:ensure_cors_rules"] do
|
||||||
ENV["DISCOURSE_S3_UPLOAD_ASSETS_RAKE_THREAD_POOL_SIZE"] || Concurrent.processor_count,
|
ENV["DISCOURSE_S3_UPLOAD_ASSETS_RAKE_THREAD_POOL_SIZE"] || Concurrent.processor_count,
|
||||||
)
|
)
|
||||||
|
|
||||||
assets.each { |asset| pool.post { upload(*asset) } }
|
logger = Logger.new(STDOUT)
|
||||||
|
assets.each { |asset| pool.post { upload(*asset, logger:) } }
|
||||||
|
|
||||||
pool.shutdown
|
pool.shutdown
|
||||||
pool.wait_for_termination
|
pool.wait_for_termination
|
||||||
|
|
Loading…
Reference in New Issue
Block a user