-
Notifications
You must be signed in to change notification settings - Fork 368
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
[Fix #469] Print log progress on import rake task #787
Merged
Vitalina-Vakulchyk
merged 19 commits into
master
from
print-log-progress-on-import-rake-task
Apr 23, 2021
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
34e8f5c
[Fix #469] Print log progress on import rake task
Vitalina-Vakulchyk 00f9f17
Resolve conflicts after rebasing
Vitalina-Vakulchyk 0b3a054
Change type option to index for ActiveSupport::Notifications.instrume…
Vitalina-Vakulchyk 05ad877
Add thread_safe_progress_bar file
Vitalina-Vakulchyk 65b7956
Fix argument order of IMPORT_WORKER block
9e30ae1
Add title method to ThreadSafeProgressBar class and use it during import
Vitalina-Vakulchyk c346ece
Revert "Add title method to ThreadSafeProgressBar class and use it du…
Vitalina-Vakulchyk be5dc7d
Comment progressbar output spec for Import
Vitalina-Vakulchyk 9e541b4
Add sleep to progressbar spec
Vitalina-Vakulchyk ed997f3
Increase sleep to 3 in progressbar spec
Vitalina-Vakulchyk 97d52ad
Temporary remove thread for ThreadSafeProgressBar class
Vitalina-Vakulchyk 757f0f4
Remove sleep to 3 in progressbar spec
Vitalina-Vakulchyk f74a140
WIP
cca173c
Inspect connection reuse
0c34085
This should pass
e396e92
WIP
96f9beb
WIP
d76dd3f
Remove rescue during import
Vitalina-Vakulchyk 8740d69
Remove pry
Vitalina-Vakulchyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Chewy | ||
class Index | ||
module Import | ||
# This class performs the threading for parallel import to avoid concurrency during progressbar output. | ||
# | ||
# @see Chewy::Type::Import::ClassMethods#import with `parallel: true` option | ||
class ThreadSafeProgressBar | ||
def initialize(enabled) | ||
@enabled = enabled | ||
|
||
return unless @enabled | ||
|
||
@mutex = Mutex.new | ||
@released = false | ||
@progressbar = ProgressBar.create total: nil | ||
Thread.new do | ||
ActiveRecord::Base.connection_pool.with_connection do | ||
@mutex.synchronize { @released = true } | ||
@progressbar.total = yield | ||
end | ||
end | ||
end | ||
|
||
def increment(value) | ||
return unless @enabled | ||
|
||
@mutex.synchronize do | ||
@progressbar.progress += value | ||
end | ||
end | ||
|
||
def wait_until_ready | ||
return true unless @enabled | ||
|
||
@mutex.synchronize { @released } until @released | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
require 'database_cleaner' | ||
|
||
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'file::memory:?cache=shared', pool: 10) | ||
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'file::memory:?cache=shared', pool: 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be interesting to explain here that test suite doesn't run properly with more than one database connection, otherwise it does not find tables |
||
ActiveRecord::Base.logger = Logger.new('/dev/null') | ||
if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks) | ||
ActiveRecord::Base.raise_in_transactional_callbacks = true | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have been in the
unreleased
section, between lines 7 and 9. Or probably better in the new features sections (5-7).