Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const checkStatus = async (): Promise => {
let result;
try {
const ex = await this.get(`/jobs/${this._jobId}/ex`, options);
if (exId && ex.ex_id !== exId) {
console.warn(`[WARNING] the execution ${ex.ex_id} has changed from ${exId}`);
}
exId = ex.ex_id;
result = ex._status;
} catch (err) {
if (/(timeout|timedout)/i.test(toString(err))) {
await pDelay(intervalMs);
return checkStatus();
}
throw err;
}
if (result === target) {
return result;
}
// These are terminal states for a job so if we're not explicitly
// watching for these then we need to stop waiting as the job
// status won't change further.
if (terminal[result]) {
throw new TSError(
`Job cannot reach the target status, "${target}", because it is in the terminal state, "${result}"`,
{ context: { lastStatus: result } }
const checkStatus = async (): Promise => {
let result;
try {
result = await this.status(options);
} catch (err) {
if (/(timeout|timedout)/i.test(toString(err))) {
await pDelay(intervalMs);
return checkStatus();
}
throw err;
}
if (result === target) {
return result;
}
// These are terminal states for a job so if we're not explicitly
// watching for these then we need to stop waiting as the job
// status won't change further.
if (terminal[result]) {
throw new TSError(
`Execution cannot reach the target status, "${target}", because it is in the terminal state, "${result}"`,
{ context: { lastStatus: result } }