import type { ActionType } from "@garden-io/grow-sdk/declarations/action-type"; import type { ExecutedActionImpl, ResolvedActionImpl } from "../actions/base"; import type { ValidResultType } from "../tasks/base-action"; /** * TODO @eysi: Review and improve this text * * Following is a description of the the lifecycle of an individual action execution as emitted to Cloud. * * Note that the internal semantics are slightly different (e.g. Grow uses "ready" instead of "cached" internally). * * The state transitions that take place when an action goes through the standard "check status and execute the * action if no up-to date result exists" flow (as is done in the primary task classes) is as follows: * * ``` * initial state: "getting-status" * final state: "cached", ready" or "failed" * * "getting-status" -> "cached" | "not-ready" * "not-ready" -> "processing" * "processing" -> "ready" | "failed" * ``` * * See also the following state transition diagram (created with https://asciiflow.com): * * ┌──────► (No-op, done) * │ * │ false * │ * ┌──► cached ──► force? ──┤ * │ │ * getting-status ──┤ │ true ┌──► failed * │ │ │ * └──► not-ready ─────────┴─────► processing ──┤ * │ * └──► ready * * The states have the following semantics: * * - `"unknown"`: A null state used e.g. by default/no-op action handlers. * * - `"getting-status"`: The status of the action is being checked/fetched. * - For example, for a container build status check, this might involve querying a container registry to see if a * build exists for the requested action's version. * - Or for a Kubernetes deployment, this might involve checking if the requested resources are already live and up * to date. * * - `"cached"`: This state indicates a cache hit. An up-to-date result exists for the action. * - This state can be reached e.g. when a status check indicates that an up-to-date build artifact / deployed * resource / test result / run result already exists. * * - `"ready"`: The action was executed successfully, and an up-to-date result exists for the action. * - This state can be reached by successfully processing the action after getting a `"not-ready"` state from the * status check. * - Think of this as "succeeded". * - Note that in the case of Test actions, the action itself will return a "ready" state even if the test itself * failed, because the action execution was successful. * * - `"not-ready"`: No result (or no healthy result) for the action exists with the requested version. * - This state is reached by a status check that doesn't find an up-to-date result (e.g. no up-to-date container * image, or a deployed resource that's missing, unhealthy, stopped or out of date with the requested action's * version). * * - `"processing"`: The action is being executed. * * - `"failed"`: Getting the status or processing the action failed with an unexpected error so no up-to-date * result was created for the action. * - Note that in the case of Test actions, this does not suggest that the underlying test failed, but rather * that the action itself failed and the test status is simply unknown. */ export type ActionState = "ready" | "processing" | "failed" | "not-ready" | "cached" | "getting-status" | "unknown"; type OperationType = "getStatus" | "process"; type ActionCompleteState = "ready" | "not-ready" | "cached"; type BaseEventStatusPayloadParams = ResolvedActionImpl> = { action: A; force: boolean; operation: OperationType; startedAt: Date; sessionId: string; }; type GetStatusEventPayloadParams = Omit; type ProcessingEventPayloadParams = Omit; type FailedEventPayloadParams = BaseEventStatusPayloadParams; type CompleteEventPayloadParams = BaseEventStatusPayloadParams> & { result: R; state: ActionState; }; export declare function makeActionStatusPayloadBase({ action, force, operation, startedAt, sessionId, }: BaseEventStatusPayloadParams): { actionName: string; actionVersion: string; actionType: string; actionUid: string; actionOutputs: {}; sessionId: string; startedAt: Date; operation: OperationType; force: boolean; }; /** * The payload for the event that's emitted before getting the action status, ahead * of actually processing it. * * After the status has been fetched we emit an action complete (e.g. "cached" / "not-ready") or action failed event. */ export declare function makeActionGetStatusPayload({ action, force, startedAt, sessionId }: GetStatusEventPayloadParams): { actionState: "getting-status"; status: { state: "unknown"; }; actionName: string; actionVersion: string; actionType: string; actionUid: string; actionOutputs: {}; sessionId: string; startedAt: Date; operation: OperationType; force: boolean; }; /** * The payload for the event that's emitted _before_ processing an action (but _after_ getting its status.) * * After processing we emit an action complete (i.e. "ready") or action failed event. */ export declare function makeActionProcessingPayload({ action, force, startedAt, sessionId }: ProcessingEventPayloadParams): { actionState: "processing"; status: { state: "running"; }; actionName: string; actionVersion: string; actionType: string; actionUid: string; actionOutputs: {}; sessionId: string; startedAt: Date; operation: OperationType; force: boolean; }; /** * The payload for the event that's emitted after we fetch the action status successfully OR after we process * the action successfully. */ export declare function makeActionCompletePayload({ result, state, action, force, operation, startedAt, sessionId, }: CompleteEventPayloadParams): { completedAt: Date; actionState: ActionCompleteState; status: { state: "failed" | "succeeded"; }; actionName: string; actionVersion: string; actionType: string; actionUid: string; actionOutputs: {}; sessionId: string; startedAt: Date; operation: OperationType; force: boolean; }; /** * The payload for the event that's emitted if fetching the action status OR processing the * action fails. */ export declare function makeActionFailedPayload({ action, force, operation, startedAt, sessionId }: FailedEventPayloadParams): { completedAt: Date; actionState: "failed"; status: { state: "unknown"; }; actionName: string; actionVersion: string; actionType: string; actionUid: string; actionOutputs: {}; sessionId: string; startedAt: Date; operation: OperationType; force: boolean; }; export {};