Skip to content

Commit

Permalink
Restore polling in pandaReqwest, which is used on the usages tab
Browse files Browse the repository at this point in the history
  • Loading branch information
rhystmills committed Nov 19, 2024
1 parent a546025 commit e4ff8cb
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions public/video-ui/src/services/pandaReqwest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ const checkStatus = (res) => {
}
}

Check warning on line 10 in public/video-ui/src/services/pandaReqwest.js

View workflow job for this annotation

GitHub Actions / CI

Missing semicolon

export const pandaFetch = (url, body) => {
return new Promise(function(resolve, reject) {
export const poll = (url, body, timeout) => {
const endTime = Number(new Date()) + timeout;
const interval = 100;

const makeRequest = (resolve, reject) => {
fetch(url, body)
.then(checkStatus)
.then(response => response.json())
.then(res => {
resolve(res)}
)
.catch(err => {
.then(checkStatus)
.then(response => response.json())
.then(res => {
resolve(res)}

Check warning on line 21 in public/video-ui/src/services/pandaReqwest.js

View workflow job for this annotation

GitHub Actions / CI

Missing semicolon
)
.catch(err => {
if (Number(new Date()) < endTime) {
if (err.status == 419) {
const store = getStore();
const reauthUrl = store.getState().config.reauthUrl;
Expand All @@ -32,15 +36,20 @@ export const pandaFetch = (url, body) => {
error => {
throw error;
});

} else {
reject(err);
setTimeout(makeRequest, interval, resolve, reject);
}
});
});
}
} else {
reject(err);
}
});
};

return new Promise(makeRequest);
};

export const pandaReqwest = (reqwestBody) => {
// when `timeout` > 0, the request will be retried every 100ms until success or timeout
export const pandaReqwest = (reqwestBody, timeout = 0) => {
const payload = Object.assign({ method: 'get' }, reqwestBody);

if (payload.data) {
Expand All @@ -53,5 +62,5 @@ export const pandaReqwest = (reqwestBody) => {
}
}

return pandaFetch(reqwestBody.url, payload);
return poll(reqwestBody.url, payload, timeout);
}

0 comments on commit e4ff8cb

Please sign in to comment.