How to use the @atomist/automation-client/util/retry.doWithRetry function in @atomist/automation-client

To help you get started, we’ve selected a few @atomist/automation-client 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 atomist / sdm / src / internal / verify / lookFor200OnEndpointRootGet.ts View on Github external
return (inv: EndpointVerificationInvocation) => {
        const agent = new https.Agent({
            rejectUnauthorized: false,
        });
        if (!inv.url) {
           throw new Error("Verify called with null URL");
        }
        return doWithRetry(
            () => axios.get(inv.url, {httpsAgent: agent})
                .then(resp => {
                    logger.debug(`lookFor200OnEndpointRootGet: Response for ${inv.url} was ${resp.status}`);
                    if (resp.status !== 200) {
                        return Promise.reject(`Unexpected response: ${resp.status}`);
                    }
                    return Promise.resolve();
                }),
            `Try to connect to ${inv.url}`,
            retryOpts);
        // Let a failure go through
    };
}
github atomist / sdm-core / src / pack / pcf / CloudFoundryApi.ts View on Github external
public async getProcessStats(appGuid: string): Promise> {
        await this.refreshToken();
        return doWithRetry(() => axios.get(
            `${this.cf.api_url}/v3/processes/${appGuid}/stats`,
            { headers: this.authHeader},
        ), `get process stats ${appGuid}`);
    }
github atomist / sdm / src / log / RolarProgressLog.ts View on Github external
public async isAvailable() {
        const url = `${this.rolarBaseUrl}/api/logs`;
        try {
            await doWithRetry(() => this.axiosInstance.head(url),
                `check if Rolar service is available`,
                this.retryOptions);
            return true;
        } catch (e) {
            logger.warn(`Rolar logger is NOT available at ${url}: ${e}`);
            return false;
        }
    }
github atomist / sdm / src / pack / pcf / CloudFoundryApi.ts View on Github external
public async uploadPackage(appGuid: string, packageFile: ReadStream): Promise> {
        await this.refreshToken();
        const packageCreateResult = await doWithRetry(() => axios.post(`${this.cf.api_url}/v3/packages`, {
            type: "bits",
            relationships: {
                app: {
                    data: {
                        guid: appGuid,
                    },
                },
            },
        }, {headers: _.assign({}, this.authHeader, this.jsonContentHeader)}),
            `create package ${appGuid}`);
        const formData = FormData();
        formData.maxDataSize = Infinity;
        formData.append("bits", packageFile);
        const uploadHeaders = _.assign({}, this.authHeader, formData.getHeaders());
        const options = {
            method: "POST",
github atomist / sdm / src / log / RolarProgressLog.ts View on Github external
private async postLogs(isClosed: boolean): Promise {
        const closedRequestParam = isClosed ? "?closed=true" : "";
        const url = `${this.rolarBaseUrl}/api/logs/${this.logPath.join("/")}${closedRequestParam}`;
        const postingLogs = this.localLogs;
        this.localLogs = [];
        const result = await doWithRetry(() => this.axiosInstance.post(url, {
                host: os.hostname(),
                content: postingLogs,
            }, {
                headers: {"Content-Type": "application/json"},
            }).catch(axiosError =>
                 Promise.reject(new Error(`Failure post to ${url}: ${axiosError.message}`))),
            `post log to Rolar`,
            this.retryOptions).catch(e => {
                this.localLogs = postingLogs.concat(this.localLogs);
                logger.error(e);
            },
        );
        return result;
    }
github atomist / sdm-core / src / pack / pcf / CloudFoundryApi.ts View on Github external
public async stopApp(appGuid: string): Promise> {
        await this.refreshToken();
        return doWithRetry(() => axios.post(
            `${this.cf.api_url}/v3/apps/${appGuid}/actions/stop`,
            undefined,
            { headers: this.authHeader},
        ), `stop app ${appGuid}`);
    }
github atomist / sdm-core / src / pack / pcf / CloudFoundryApi.ts View on Github external
public async deleteApp(appGuid: string): Promise> {
        await this.refreshToken();
        return doWithRetry(() => axios.delete(
            `${this.cf.api_url}/v3/apps/${appGuid}`,
            { headers: this.authHeader},
        ), `delete app ${appGuid}`);
    }
github atomist / sdm / src / pack / pcf / CloudFoundryApi.ts View on Github external
public async setCurrentDropletForApp(appGuid: string, dropletGuid: string): Promise> {
        await this.refreshToken();
        return doWithRetry(() => axios.patch(
            `${this.cf.api_url}/v3/apps/${appGuid}/relationships/current_droplet`,
            { data: { guid: dropletGuid } },
            { headers: _.assign({}, this.authHeader, this.jsonContentHeader)},
        ), `set current droplet for app ${appGuid}`);
    }
github atomist / sdm / src / pack / pcf / CloudFoundryApi.ts View on Github external
public async getProcessStats(appGuid: string): Promise> {
        await this.refreshToken();
        return doWithRetry(() => axios.get(
            `${this.cf.api_url}/v3/processes/${appGuid}/stats`,
            { headers: this.authHeader},
        ), `get process stats ${appGuid}`);
    }
github atomist / sdm / src / pack / pcf / CloudFoundryApi.ts View on Github external
public async buildDroplet(packageGuid: string): Promise> {
        await this.refreshToken();
        const buildResult = await doWithRetry(() => axios.post(`${this.cf.api_url}/v3/builds`, {
                package: {
                    guid: packageGuid,
                },
            },
            {headers: _.assign({}, this.authHeader, this.jsonContentHeader)}),
            `build droplet ${packageGuid}`);
        return this.retryUntilCondition(
            async () => {
                await this.refreshToken();
                return doWithRetry(() => axios.get(buildResult.data.links.self.href, {headers: this.authHeader}),
                    `get build for package ${buildResult.data.guid}`);
                },
                r => r.data.state === "STAGED",
            r => r.data.state === "FAILED" || r.data.state === "EXPIRED",
        );
    }