Skip to content

Commit 0eb7bbb

Browse files
author
Raphaël Droz
authored
chunk.abort() to set FlowFile status to "pending" instead of "uploading" (#349)
status: When a chunk abort(), eg when parent's FlowFile.pause(), set its status back to pending (and pendingRetry === true) since it's not actually "uploading" anymore
1 parent 2657626 commit 0eb7bbb

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

dist/flow.js

Lines changed: 20 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/flow.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/FlowChunk.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,11 @@ export default class FlowChunk {
444444
status(isTest) {
445445
if (this.readState === 1) {
446446
return 'reading';
447-
} else if (this.pendingRetry || this.preprocessState === 1) {
447+
} else if (this.preprocessState === 1) {
448448
// if pending retry then that's effectively the same as actively uploading,
449449
// there might just be a slight delay before the retry starts
450450
return 'uploading';
451-
} else if (!this.xhr) {
451+
} else if (!this.xhr || this.pendingRetry) {
452452
return 'pending';
453453
} else if (this.xhr.readyState < 4) {
454454
// Status is really 'OPENED', 'HEADERS_RECEIVED'

src/FlowFile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,16 @@ export default class FlowFile {
196196
abort(reset) {
197197
this.currentSpeed = 0;
198198
this.averageSpeed = 0;
199-
var chunks = this.chunks;
200199
if (reset) {
201200
this.chunks = [];
202201
}
203-
each(chunks, function (c) {
202+
for (let c of this.chunks) {
204203
if (c.status() === 'uploading') {
205204
c.abort();
205+
c.pendingRetry = true;
206206
this.flowObj.uploadNextChunk();
207207
}
208-
}, this);
208+
}
209209
}
210210

211211
/**

test/uploadSpec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ describe('upload file', function() {
127127
it('should pause and resume file', function () {
128128
flow.opts.chunkSize = 1;
129129
flow.opts.simultaneousUploads = 2;
130+
flow.opts.testChunks = false;
130131
flow.addFile(new Blob(['1234']));
131132
flow.addFile(new Blob(['56']));
132133
var files = flow.files;
@@ -271,14 +272,15 @@ describe('upload file', function() {
271272
flow.addFile(new Blob(['12']));
272273
var file = flow.files[0];
273274
flow.upload();
275+
expect(file.chunks[0].status()).toBe('uploading');
274276
expect(xhr.requests.length).toBe(1);
275277

276278
xhr.requests[0].respond(400);
277279
expect(xhr.requests.length).toBe(1);
278280
expect(error).not.toHaveBeenCalled();
279281
expect(success).not.toHaveBeenCalled();
280282
expect(retry).toHaveBeenCalled();
281-
expect(file.chunks[0].status()).toBe('uploading');
283+
expect(file.chunks[0].status()).toBe('pending');
282284

283285
jasmine.clock().tick(100);
284286
expect(xhr.requests.length).toBe(2);

0 commit comments

Comments
 (0)