Skip to content
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

Fix: Don't wait when rep status is none #871

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/lib/RepStatus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventEmitter from 'events';
import { get, appendAuthParams } from './util';
import { STATUS_SUCCESS, STATUS_VIEWABLE } from './constants';
import { STATUS_SUCCESS, STATUS_VIEWABLE, STATUS_PENDING, STATUS_NONE } from './constants';
import PreviewError from './PreviewError';
import Timer from './Timer';
import { ERROR_CODE, LOAD_METRIC } from './events';
Expand Down Expand Up @@ -142,19 +142,21 @@ class RepStatus extends EventEmitter {
this.resolve();
break;

case 'none':
case 'pending':
case STATUS_NONE:
case STATUS_PENDING:
// If we are doing some logging, log that the file needed conversion
if (this.logger) {
this.logger.setUnConverted();
}

this.emit('conversionpending');

// Check status again after delay
// Check status again after delay or
// If status is none, request immediately since conversion
// won't kick off until representation is requested
this.statusTimeout = setTimeout(() => {
this.updateStatus();
}, STATUS_UPDATE_INTERVAL_MS);
}, status === STATUS_NONE ? 0 : STATUS_UPDATE_INTERVAL_MS);
break;

default:
Expand Down
13 changes: 12 additions & 1 deletion src/lib/__tests__/RepStatus-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('lib/RepStatus', () => {
expect(repStatus.emit).to.be.calledWith('conversionpending');
});

it('should update status after a timeout', () => {
it('should update status after a timeout and update interval when pending', () => {
const clock = sinon.useFakeTimers();
repStatus.logger = false;
sandbox.mock(repStatus).expects('updateStatus');
Expand All @@ -261,6 +261,17 @@ describe('lib/RepStatus', () => {
clock.restore();
});

it('should update status immediately after a timeout when none', () => {
const clock = sinon.useFakeTimers();
repStatus.logger = false;
sandbox.mock(repStatus).expects('updateStatus');
repStatus.representation.status.state = 'none';

repStatus.handleResponse();
clock.tick(1);
clock.restore();
});

it('should stop a convert time Timer on success converting', () => {
repStatus.representation.status.state = STATUS_SUCCESS;
const tag = Timer.createTag(fileId, LOAD_METRIC.convertTime);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ export const ORIGINAL_REP_NAME = 'ORIGINAL';
export const PRELOAD_REP_NAME = 'jpg';

export const STATUS_ERROR = 'error';
export const STATUS_NONE = 'none';
export const STATUS_PENDING = 'pending';
export const STATUS_SUCCESS = 'success';
export const STATUS_VIEWABLE = 'viewable';
export const STATUS_PENDING = 'pending';

// X-Rep-Hints for Representations API
export const X_REP_HINT_BASE = '[3d][pdf][text][mp3]';
Expand Down