How to use the @atomist/sdm.SdmGoalState.canceled function in @atomist/sdm

To help you get started, we’ve selected a few @atomist/sdm 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-core / lib / handlers / events / delivery / goals / FulfillGoalOnRequested.ts View on Github external
await reportStart(sdmGoal, progressLog);
            const start = Date.now();

            try {
                const result = await executeGoal(
                    {
                        projectLoader: this.configuration.sdm.projectLoader,
                        goalExecutionListeners: this.goalExecutionListeners,
                    },
                    {
                        ...implementation,
                        projectListeners: [...toArray(implementation.projectListeners || []), ...listeners],
                    },
                    goalInvocation);
                const terminatingStates = [
                    SdmGoalState.canceled,
                    SdmGoalState.failure,
                    SdmGoalState.skipped,
                    SdmGoalState.stopped,
                    SdmGoalState.success,
                    SdmGoalState.waiting_for_approval,
                ];
                if (!result || !result.state || terminatingStates.includes(result.state)) {
                    await reportEndAndClose(result, start, progressLog);
                }
                return {
                    ...result,
                    // successfully handled event even if goal failed
                    code: 0,
                };
            } catch (e) {
                e.message = `Goal executor threw exception: ${e.message}`;
github atomist / sdm-core / lib / handlers / events / delivery / goals / SkipDownstreamGoalsOnGoalFailure.ts View on Github external
const goalsToSkip = goals.filter(g => isDependentOn(failedGoal, g, mapKeyToGoal(goals)))
            .filter(g => g.state === "planned");

        let failedGoalState;
        let failedGoalDescription;
        switch (failedGoal.state) {
            case SdmGoalState.failure:
                failedGoalDescription = "failed";
                failedGoalState = SdmGoalState.skipped;
                break;
            case SdmGoalState.stopped:
                failedGoalDescription = "stopped goals";
                failedGoalState = SdmGoalState.skipped;
                break;
            case SdmGoalState.canceled:
                failedGoalDescription = "was canceled";
                failedGoalState = SdmGoalState.canceled;
                break;
        }
        await Promise.all(goalsToSkip.map(g => updateGoal(context, g, {
            state: failedGoalState,
            description: `${failedGoalState === SdmGoalState.skipped ? "Skipped" : "Canceled"
            } ${g.name} because ${failedGoal.name} ${failedGoalDescription}`,
        })));

        return Success;
    }
}
github atomist / sdm-core / lib / pack / goal-state / manageGoalSets.ts View on Github external
},
        options: {
            ...QueryNoCacheOptions,
            log: configurationValue("sdm.query.logging", false),
        },
    })).SdmGoal;

    const state = !!options && !!options.state ? options.state : SdmGoalState.canceled;

    for (const goal of gs) {
        if (goal.ts < end) {
            logger.debug(
                `Canceling goal '${goal.uniqueName}' of goal set '${goal.goalSetId}' because it timed out after '${formatDuration(timeout)}'`);
            let description = `${state === SdmGoalState.canceled ? "Canceled" : "Failed"}: ${goal.name}`;
            if (!!goal.descriptions) {
                if (state === SdmGoalState.canceled && !!goal.descriptions.canceled) {
                    description = goal.descriptions.canceled;
                } else if (state === SdmGoalState.failure && !!goal.descriptions.failed) {
                    description = goal.descriptions.failed;
                }
            }
            await updateGoal(
                ctx,
                goal as any,
                {
                    state,
                    description,
                    phase: `${formatDuration(timeout)} timeout`,
                });
        }
    }
}
github atomist / sdm-core / lib / pack / goal-state / manageGoalSets.ts View on Github external
? options.timeout
        : _.get(sdm.configuration, "sdm.goal.inProcessTimeout", 1000 * 60 * 60);
    const end = Date.now() - timeout;

    const gs = (await ctx.graphClient.query({
        name: "InProcessSdmGoals",
        variables: {
            registration: [sdm.configuration.name],
        },
        options: {
            ...QueryNoCacheOptions,
            log: configurationValue("sdm.query.logging", false),
        },
    })).SdmGoal;

    const state = !!options && !!options.state ? options.state : SdmGoalState.canceled;

    for (const goal of gs) {
        if (goal.ts < end) {
            logger.debug(
                `Canceling goal '${goal.uniqueName}' of goal set '${goal.goalSetId}' because it timed out after '${formatDuration(timeout)}'`);
            let description = `${state === SdmGoalState.canceled ? "Canceled" : "Failed"}: ${goal.name}`;
            if (!!goal.descriptions) {
                if (state === SdmGoalState.canceled && !!goal.descriptions.canceled) {
                    description = goal.descriptions.canceled;
                } else if (state === SdmGoalState.failure && !!goal.descriptions.failed) {
                    description = goal.descriptions.failed;
                }
            }
            await updateGoal(
                ctx,
                goal as any,
github atomist / sdm-core / lib / handlers / events / delivery / goals / SkipDownstreamGoalsOnGoalFailure.ts View on Github external
.filter(g => g.state === "planned");

        let failedGoalState;
        let failedGoalDescription;
        switch (failedGoal.state) {
            case SdmGoalState.failure:
                failedGoalDescription = "failed";
                failedGoalState = SdmGoalState.skipped;
                break;
            case SdmGoalState.stopped:
                failedGoalDescription = "stopped goals";
                failedGoalState = SdmGoalState.skipped;
                break;
            case SdmGoalState.canceled:
                failedGoalDescription = "was canceled";
                failedGoalState = SdmGoalState.canceled;
                break;
        }
        await Promise.all(goalsToSkip.map(g => updateGoal(context, g, {
            state: failedGoalState,
            description: `${failedGoalState === SdmGoalState.skipped ? "Skipped" : "Canceled"
            } ${g.name} because ${failedGoal.name} ${failedGoalDescription}`,
        })));

        return Success;
    }
}
github atomist / sdm-core / lib / pack / goal-state / manageGoalSets.ts View on Github external
variables: {
            registration: [sdm.configuration.name],
        },
        options: {
            ...QueryNoCacheOptions,
            log: configurationValue("sdm.query.logging", false),
        },
    })).SdmGoal;

    const state = !!options && !!options.state ? options.state : SdmGoalState.canceled;

    for (const goal of gs) {
        if (goal.ts < end) {
            logger.debug(
                `Canceling goal '${goal.uniqueName}' of goal set '${goal.goalSetId}' because it timed out after '${formatDuration(timeout)}'`);
            let description = `${state === SdmGoalState.canceled ? "Canceled" : "Failed"}: ${goal.name}`;
            if (!!goal.descriptions) {
                if (state === SdmGoalState.canceled && !!goal.descriptions.canceled) {
                    description = goal.descriptions.canceled;
                } else if (state === SdmGoalState.failure && !!goal.descriptions.failed) {
                    description = goal.descriptions.failed;
                }
            }
            await updateGoal(
                ctx,
                goal as any,
                {
                    state,
                    description,
                    phase: `${formatDuration(timeout)} timeout`,
                });
        }
github atomist / sdm-core / lib / pack / k8s / KubernetesJobDeletingGoalCompletionListener.ts View on Github external
return async gi => {
            const goalEvent = gi.completedGoal;

            if (goalEvent.state === SdmGoalState.in_process) {
                return;
            }

            if (goalEvent.state === SdmGoalState.canceled && !(await cancelableGoal(goalEvent, gi.configuration))) {
                return;
            }

            const selector = `atomist.com/goal-set-id=${goalEvent.goalSetId},atomist.com/creator=${sanitizeName(this.sdm.configuration.name)}`;
            let jobs;

            try {
                jobs = await listJobs(selector);
            } catch (e) {
                logger.warn(`Failed to read k8s jobs: ${prettyPrintError(e)}`);
                return;
            }

            logger.debug(
                `Found k8s jobs for goal set '${goalEvent.goalSetId}': '${
                    jobs.map(j => `${j.metadata.namespace}:${j.metadata.name}`).join(", ")}'`);