-
Notifications
You must be signed in to change notification settings - Fork 867
Add DownloadInitiated, Failed and Completed events #4079
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
Open
Parent:
Add UploadWithResponseAsync API
GarrettBeatty
wants to merge
1
commit into
GarrettBeatty/stacked/4
Choose a base branch
from
GarrettBeatty/stacked/10
base: GarrettBeatty/stacked/4
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.
Open
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions
11
generator/.DevConfigs/9d07dc1e-d82d-4f94-8700-c7b57f872123.json
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,11 @@ | ||
| { | ||
| "services": [ | ||
| { | ||
| "serviceName": "S3", | ||
| "type": "minor", | ||
| "changeLogMessages": [ | ||
| "Added DownloadInitiatedEvent, DownloadCompletedEvent, and DownloadFailedEvent for downloads." | ||
| ] | ||
| } | ||
| ] | ||
| } |
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 |
|---|---|---|
|
|
@@ -33,12 +33,17 @@ internal partial class DownloadCommand : BaseCommand<TransferUtilityDownloadResp | |
| public override async Task<TransferUtilityDownloadResponse> ExecuteAsync(CancellationToken cancellationToken) | ||
| { | ||
| ValidateRequest(); | ||
|
|
||
| FireTransferInitiatedEvent(); | ||
|
|
||
| GetObjectRequest getRequest = ConvertToGetObjectRequest(this._request); | ||
|
|
||
| var maxRetries = _s3Client.Config.MaxErrorRetry; | ||
| var retries = 0; | ||
| bool shouldRetry = false; | ||
| string mostRecentETag = null; | ||
| TransferUtilityDownloadResponse lastSuccessfulMappedResponse = null; | ||
| long? totalBytesFromResponse = null; // Track total bytes once we have response headers | ||
| do | ||
| { | ||
| shouldRetry = false; | ||
|
|
@@ -54,12 +59,16 @@ public override async Task<TransferUtilityDownloadResponse> ExecuteAsync(Cancell | |
| using (var response = await this._s3Client.GetObjectAsync(getRequest, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false)) | ||
| { | ||
| // Capture total bytes from response headers as soon as we get them | ||
| totalBytesFromResponse = response.ContentLength; | ||
|
|
||
| if (!string.IsNullOrEmpty(mostRecentETag) && !string.Equals(mostRecentETag, response.ETag)) | ||
| { | ||
| //if the eTag changed, we need to retry from the start of the file | ||
| mostRecentETag = response.ETag; | ||
| getRequest.ByteRange = null; | ||
| retries = 0; | ||
| Interlocked.Exchange(ref _totalTransferredBytes, 0); | ||
GarrettBeatty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| shouldRetry = true; | ||
| WaitBeforeRetry(retries); | ||
| continue; | ||
|
|
@@ -101,6 +110,8 @@ await response.WriteResponseStreamToFileAsync(this._request.FilePath, false, can | |
| await response.WriteResponseStreamToFileAsync(this._request.FilePath, true, cancellationToken) | ||
| .ConfigureAwait(continueOnCapturedContext: false); | ||
| } | ||
|
|
||
| lastSuccessfulMappedResponse = ResponseMapper.MapGetObjectResponse(response); | ||
| } | ||
| } | ||
| catch (Exception exception) | ||
|
|
@@ -109,6 +120,9 @@ await response.WriteResponseStreamToFileAsync(this._request.FilePath, true, canc | |
| shouldRetry = HandleExceptionForHttpClient(exception, retries, maxRetries); | ||
| if (!shouldRetry) | ||
| { | ||
| // Pass total bytes if we have them from response headers, otherwise -1 for unknown | ||
| FireTransferFailedEvent(this._request.FilePath, Interlocked.Read(ref _totalTransferredBytes), totalBytesFromResponse ?? -1); | ||
|
|
||
| if (exception is IOException) | ||
| { | ||
| throw; | ||
|
|
@@ -131,8 +145,9 @@ await response.WriteResponseStreamToFileAsync(this._request.FilePath, true, canc | |
| WaitBeforeRetry(retries); | ||
| } while (shouldRetry); | ||
|
|
||
| // TODO map and return response | ||
| return new TransferUtilityDownloadResponse(); | ||
| FireTransferCompletedEvent(lastSuccessfulMappedResponse, this._request.FilePath, Interlocked.Read(ref _totalTransferredBytes), totalBytesFromResponse ?? -1); | ||
|
|
||
| return lastSuccessfulMappedResponse; | ||
|
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. copilot is saying that this could potentially be null but based on my reading of the code, if there is any failure we will throw exception early on, so it can never be null. thoughts? |
||
| } | ||
|
|
||
| private static bool HandleExceptionForHttpClient(Exception exception, int retries, int maxRetries) | ||
|
|
||
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.