]>
cat aescling's git repositories - mastodon.git/blob - lib/mastodon/cli_helper.rb
ed22f44b2bfd0b09222312a82e4453cd80d3a032
1 # frozen_string_literal: true
3 dev_null
= Logger
.new('/dev/null')
5 Rails
.logger
= dev_null
6 ActiveRecord
::Base.logger
= dev_null
7 ActiveJob
::Base.logger
= dev_null
8 HttpLog
.configuration
.logger
= dev_null
9 Paperclip
.options
[:log] = false
10 Chewy
.logger
= dev_null
18 def create_progress_bar(total
= nil)
19 ProgressBar
.create(total
: total
, format
: '%c/%u |%b%i| %e')
22 def parallelize_with_progress(scope
)
23 if options
[:concurrency] < 1
24 say('Cannot run with this concurrency setting, must be at least 1', :red)
28 ActiveRecord
::Base.configurations
[Rails
.env]['pool'] = options
[:concurrency] +
1
30 progress
= create_progress_bar(scope
.count
)
31 pool
= Concurrent
::FixedThreadPool.new(options
[:concurrency])
32 total
= Concurrent
::AtomicFixnum.new(0)
33 aggregate
= Concurrent
::AtomicFixnum.new(0)
35 scope
.reorder(nil).find_in_batches
do |items
|
39 futures
<< Concurrent
::Future.execute(executor
: pool
) do
41 if !progress
.total
.nil? && progress
.progress +
1 > progress
.total
42 # The number of items has changed between start and now,
43 # since there is no good way to predict the final count from
44 # here, just change the progress bar to an indeterminate one
49 progress
.log("Processing #{item.id}") if options
[:verbose]
51 result
= ActiveRecord
::Base.connection_pool
.with_connection
do
55 aggregate
.increment(result
) if result
.is_a
?(Integer
)
57 progress
.log pastel
.red("Error processing #{item.id}: #{e}")
64 total
.increment(items
.size
)
70 [total
.value
, aggregate
.value
]
74 @pastel ||= Pastel
.new
This page took 0.082043 seconds and 2 git commands to generate.