-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Seeder progress indicators #7510
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
Draft
withinfocus
wants to merge
4
commits into
main
Choose a base branch
from
seeder-progress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,48 @@ | ||
| ο»Ώnamespace Bit.Seeder.Pipeline; | ||
|
|
||
| /// <summary> | ||
| /// Batches <see cref="PhaseAdvanced"/> events so a sequential loop over N items emits at most ~100 events. | ||
| /// Caller is responsible for calling <see cref="PhaseStarted"/>/<see cref="PhaseCompleted"/>; this | ||
| /// type only handles per-iteration flushing. Not thread-safe β parallel loops should use thread-local | ||
| /// counters and report directly via <see cref="IProgress{T}.Report"/>. | ||
| /// </summary> | ||
| internal sealed class ProgressTicker | ||
| { | ||
| private readonly IProgress<SeederProgressEvent>? _progress; | ||
| private readonly string _phase; | ||
| private readonly int _batchSize; | ||
| private int _pending; | ||
|
|
||
| internal ProgressTicker(IProgress<SeederProgressEvent>? progress, string phase, int total) | ||
| { | ||
| _progress = progress; | ||
| _phase = phase; | ||
| _batchSize = Math.Max(1, total / 100); | ||
| } | ||
|
|
||
| internal void Tick() | ||
| { | ||
| if (_progress is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| _pending++; | ||
| if (_pending >= _batchSize) | ||
| { | ||
| _progress.Report(new PhaseAdvanced(_phase, _pending)); | ||
| _pending = 0; | ||
| } | ||
| } | ||
|
|
||
| internal void Flush() | ||
| { | ||
| if (_progress is null || _pending <= 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| _progress.Report(new PhaseAdvanced(_phase, _pending)); | ||
| _pending = 0; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,16 @@ | ||
| ο»Ώnamespace Bit.Seeder.Pipeline; | ||
|
|
||
| /// <summary> | ||
| /// Events emitted by the seeder pipeline for progress reporting. | ||
| /// Consumed via <see cref="System.IProgress{T}"/> to keep the library UI-agnostic. | ||
| /// </summary> | ||
| public abstract record SeederProgressEvent(string Phase); | ||
|
|
||
| /// <summary>Emitted when a phase begins. <paramref name="Total"/> is null for indeterminate work.</summary> | ||
| public sealed record PhaseStarted(string Phase, int? Total) : SeederProgressEvent(Phase); | ||
|
|
||
| /// <summary>Emitted periodically as a phase makes progress. <paramref name="Delta"/> is incremental, not cumulative.</summary> | ||
| public sealed record PhaseAdvanced(string Phase, int Delta) : SeederProgressEvent(Phase); | ||
|
|
||
| /// <summary>Emitted when a phase completes.</summary> | ||
| public sealed record PhaseCompleted(string Phase) : SeederProgressEvent(Phase); |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
β»οΈ
SeederPhasesis here solely to holdCommittingToDatabase, whileCreateCiphersStep,CreateCollectionsStep,CreateGroupsStep,CreateUsersStep, andGeneratePersonalCiphersStepeach define their own file-localprivate const string Phase.Let's put them all into this simple class of constants, move it to it's own file, and use it for phase definitions since multiple patterns invites drift.