Skip to content

Commit

Permalink
switch from 409 to 503 for upload being processed
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelk committed Jun 8, 2021
1 parent c99d638 commit 0cd0f98
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
token: this.authService.getAccessToken(),
uploaderClass: UploaderXFormData,
retryConfig: {
maxAttempts: 6,
shouldRetry: (code: number) => {
return code < 400 || code >= 501
maxAttempts: 30, // maximum attempts for 503 codes, otherwise set to 6, see below
maxDelay: 120_000, // 2 min
shouldRetry: (code: number, attempts: number) => {
return code === HttpStatusCode.SERVICE_UNAVAILABLE_503 || ((code < 400 || code > 500) && attempts < 6)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions server/lib/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class Redis {

setUploadSession (uploadId: string, video?: { id: number, uuid: string }) {
return this.setObject(
uploadId,
'resumable-upload-' + uploadId,
video
? {
id: video.id.toString(),
Expand All @@ -219,11 +219,11 @@ class Redis {
}

doesUploadSessionExist (uploadId: string) {
return this.exists(uploadId)
return this.exists('resumable-upload-' + uploadId)
}

getUploadSession (uploadId: string) {
return this.getValue(uploadId)
return this.getValue('resumable-upload-' + uploadId)
}

/* ************ Keys generation ************ */
Expand Down
2 changes: 1 addition & 1 deletion server/middlewares/validators/videos/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const videosAddResumableValidator = [
if (!sessionResponse) {
res.setHeader('Retry-After', 300) // ask to retry after 5 min, knowing the upload_id is kept for up to 15 min after completion
res.fail({
status: HttpStatusCode.CONFLICT_409,
status: HttpStatusCode.SERVICE_UNAVAILABLE_503,
message: 'The upload is already being processed'
})
} else {
Expand Down
9 changes: 8 additions & 1 deletion support/doc/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2039,11 +2039,18 @@ paths:
'404':
description: upload not found
'409':
description: chunk doesn't match range or upload being processed
description: chunk doesn't match range
'422':
description: video unreadable
'429':
description: too many concurrent requests
'503':
description: upload is already being processed
headers:
'Retry-After':
schema:
type: number
example: 300
delete:
summary: Cancel the resumable upload of a video, deleting any data uploaded so far
description: Uses [a resumable protocol](https://github.com/kukhariev/node-uploadx/blob/master/proto.md) to cancel the upload of a video
Expand Down

0 comments on commit 0cd0f98

Please sign in to comment.