How to use the @terascope/job-components.pDelay function in @terascope/job-components

To help you get started, we’ve selected a few @terascope/job-components examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terascope / teraslice / packages / teraslice-client-js / src / job.ts View on Github external
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 } }
github terascope / teraslice / packages / teraslice-client-js / src / ex.ts View on Github external
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 } }