-
Notifications
You must be signed in to change notification settings - Fork 311
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
New: MultiputUpload part2 #127
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f6a5c59
New: MultiputUpload part2
debbaca
update
0aa9d51
code review
ccbb90a
update
2e984c3
tests for MultiputUpload
19744f3
tests for MultiputPart
5e2d955
cr
0410506
code review
13f4180
remove getPartsState
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @flow | ||
* @file Multiput upload base class | ||
* @author Box | ||
*/ | ||
import Base from '../Base'; | ||
import type { MultiputConfig, Options } from '../../flowTypes'; | ||
|
||
const DEFAULT_MULTIPUT_CONFIG: MultiputConfig = { | ||
digestReadahead: 5, // How many parts past those currently uploading to precompute digest for | ||
initialRetryDelayMs: 5000, // Base for exponential backoff on retries | ||
maxRetryDelayMs: 60000, // Upper bound for time between retries | ||
parallelism: 5, // Maximum number of parts to upload at a time | ||
requestTimeoutMs: 120000, // Idle timeout on part upload, overall request timeout on other requests | ||
// eslint-disable-next-line max-len | ||
retries: 5 // How many times to retry requests such as upload part or commit. Note that total number of attempts will be retries + 1 in worst case where all attempts fail. | ||
}; | ||
|
||
class BaseMultiput extends Base { | ||
config: MultiputConfig; | ||
sessionEndpoints: Object; | ||
canConsoleLog: boolean; | ||
|
||
/** | ||
* [constructor] | ||
* | ||
* @param {Options} options | ||
* @param {Object} sessionEndpoints | ||
* @param {MultiputConfig} [config] | ||
* @return {void} | ||
*/ | ||
constructor(options: Options, sessionEndpoints: Object, config?: MultiputConfig): void { | ||
super(options); | ||
|
||
this.config = config || DEFAULT_MULTIPUT_CONFIG; | ||
this.sessionEndpoints = sessionEndpoints; | ||
this.canConsoleLog = !!options.consoleLog && !!window.console && !!window.console.log; | ||
} | ||
|
||
/** | ||
* Console log a function returned message | ||
* | ||
* @param {Function} msgFunc | ||
* @return {void} | ||
*/ | ||
consoleLogFunc = (msgFunc: Function): void => { | ||
if (!this.canConsoleLog) { | ||
return; | ||
} | ||
|
||
this.consoleLog(msgFunc()); | ||
}; | ||
|
||
/** | ||
* POST log event | ||
* | ||
* @param {string} eventType | ||
* @param {string} [eventInfo] | ||
* @return {Promise} | ||
*/ | ||
logEvent = (eventType: string, eventInfo?: string) => { | ||
const data: { | ||
event_type: string, | ||
event_info?: string | ||
} = { | ||
event_type: eventType | ||
}; | ||
|
||
if (eventInfo) { | ||
data.event_info = eventInfo; | ||
} | ||
|
||
return this.xhr.post({ | ||
url: this.sessionEndpoints.logEvent, | ||
data | ||
}); | ||
}; | ||
} | ||
|
||
export default BaseMultiput; |
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.
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.
Is this still needed? Since this.consoleLog will be a noop, you can just call it without check of existance.
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.
Yes, because if you can't console log, then we won't call the function to generate the console message which could potentially be costly. see
consoleLogFunc