Skip to content

Commit 24a6d60

Browse files
authored
fix(EventuallyQueue): Poll against /health endpoint (#1305)
* fix(EventuallyQueue): Poll against /health endpoint * Clean up
1 parent a2329c1 commit 24a6d60

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/EventuallyQueue.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,14 @@ const EventuallyQueue = {
308308
}
309309
polling = setInterval(() => {
310310
const RESTController = CoreManager.getRESTController();
311-
RESTController.ajax('GET', CoreManager.get('SERVER_URL')).catch(error => {
312-
if (error !== 'Unable to connect to the Parse API') {
313-
this.stopPoll();
314-
return this.sendQueue();
315-
}
316-
});
311+
RESTController.request('GET', 'health')
312+
.then(({ status }) => {
313+
if (status === 'ok') {
314+
this.stopPoll();
315+
return this.sendQueue();
316+
}
317+
})
318+
.catch(e => e);
317319
}, ms);
318320
},
319321

src/__tests__/EventuallyQueue-test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ const RESTController = require('../RESTController');
5252
const Storage = require('../Storage');
5353
const mockXHR = require('./test_helpers/mockXHR');
5454

55+
CoreManager.setInstallationController({
56+
currentInstallationId() {
57+
return Promise.resolve('iid');
58+
},
59+
});
60+
5561
function flushPromises() {
5662
return new Promise(resolve => setImmediate(resolve));
5763
}
@@ -400,7 +406,7 @@ describe('EventuallyQueue', () => {
400406

401407
it('can poll server', async () => {
402408
jest.spyOn(EventuallyQueue, 'sendQueue').mockImplementationOnce(() => {});
403-
RESTController._setXHR(mockXHR([{ status: 107, response: { error: 'ok' } }]));
409+
RESTController._setXHR(mockXHR([{ status: 200, response: { status: 'ok' } }]));
404410
EventuallyQueue.poll();
405411
expect(EventuallyQueue.isPolling()).toBe(true);
406412
jest.runOnlyPendingTimers();

0 commit comments

Comments
 (0)