@@ -9,6 +9,7 @@ import * as bitbucket from '@backstage/plugin-scaffolder-backend-module-bitbucke
|
||||
import * as bitbucketCloud from '@backstage/plugin-scaffolder-backend-module-bitbucket-cloud';
|
||||
import * as bitbucketServer from '@backstage/plugin-scaffolder-backend-module-bitbucket-server';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { CheckpointRecord } from '@backstage/plugin-scaffolder-node';
|
||||
import { Config } from '@backstage/config';
|
||||
import { Duration } from 'luxon';
|
||||
import { executeShellCommand as executeShellCommand_2 } from '@backstage/plugin-scaffolder-node';
|
||||
@@ -47,6 +48,7 @@ import { TaskRecovery } from '@backstage/plugin-scaffolder-common';
|
||||
import { TaskSecrets as TaskSecrets_2 } from '@backstage/plugin-scaffolder-node';
|
||||
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
|
||||
import { TaskSpecV1beta3 } from '@backstage/plugin-scaffolder-common';
|
||||
import { TaskState } from '@backstage/plugin-scaffolder-node';
|
||||
import { TaskStatus as TaskStatus_2 } from '@backstage/plugin-scaffolder-node';
|
||||
import { TemplateAction as TemplateAction_2 } from '@backstage/plugin-scaffolder-node';
|
||||
import { TemplateActionOptions } from '@backstage/plugin-scaffolder-node';
|
||||
@@ -359,6 +361,7 @@ export interface CurrentClaimedTask {
|
||||
createdBy?: string;
|
||||
secrets?: TaskSecrets_2;
|
||||
spec: TaskSpec;
|
||||
state?: TaskState;
|
||||
taskId: string;
|
||||
}
|
||||
|
||||
@@ -403,6 +406,10 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
tasks: SerializedTask_2[];
|
||||
}>;
|
||||
// (undocumented)
|
||||
listCheckpoints({ taskId }: { taskId: string }): Promise<{
|
||||
state: TaskState;
|
||||
}>;
|
||||
// (undocumented)
|
||||
listEvents(options: TaskStoreListEventsOptions): Promise<{
|
||||
events: SerializedTaskEvent_2[];
|
||||
}>;
|
||||
@@ -418,6 +425,8 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
ids: string[];
|
||||
}>;
|
||||
// (undocumented)
|
||||
saveCheckpoint(options: TaskStoreStateOptions): Promise<void>;
|
||||
// (undocumented)
|
||||
shutdownTask(options: TaskStoreShutDownTaskOptions): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -519,11 +528,20 @@ export class TaskManager implements TaskContext {
|
||||
// (undocumented)
|
||||
emitLog(message: string, logMetadata?: JsonObject): Promise<void>;
|
||||
// (undocumented)
|
||||
getCheckpoints?(): Promise<
|
||||
| {
|
||||
state: TaskState;
|
||||
}
|
||||
| undefined
|
||||
>;
|
||||
// (undocumented)
|
||||
getWorkspaceName(): Promise<string>;
|
||||
// (undocumented)
|
||||
get secrets(): TaskSecrets_2 | undefined;
|
||||
// (undocumented)
|
||||
get spec(): TaskSpecV1beta3;
|
||||
// (undocumented)
|
||||
updateCheckpoint?(options: CheckpointRecord): Promise<void>;
|
||||
}
|
||||
|
||||
// @public @deprecated (undocumented)
|
||||
@@ -559,6 +577,10 @@ export interface TaskStore {
|
||||
tasks: SerializedTask[];
|
||||
}>;
|
||||
// (undocumented)
|
||||
listCheckpoints?({ taskId }: { taskId: string }): Promise<{
|
||||
state: TaskState;
|
||||
}>;
|
||||
// (undocumented)
|
||||
listEvents(options: TaskStoreListEventsOptions): Promise<{
|
||||
events: SerializedTaskEvent[];
|
||||
}>;
|
||||
@@ -573,6 +595,8 @@ export interface TaskStore {
|
||||
ids: string[];
|
||||
}>;
|
||||
// (undocumented)
|
||||
saveCheckpoint?(options: TaskStoreStateOptions): Promise<void>;
|
||||
// (undocumented)
|
||||
shutdownTask?(options: TaskStoreShutDownTaskOptions): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -610,6 +634,12 @@ export type TaskStoreShutDownTaskOptions = {
|
||||
taskId: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type TaskStoreStateOptions = {
|
||||
taskId: string;
|
||||
state?: TaskState;
|
||||
};
|
||||
|
||||
// @public
|
||||
export class TaskWorker {
|
||||
// (undocumented)
|
||||
|
||||
@@ -100,11 +100,11 @@ export class TaskManager implements TaskContext {
|
||||
}
|
||||
|
||||
async updateCheckpoint?(options: CheckpointRecord): Promise<void> {
|
||||
// drop the key
|
||||
const { key, ...value } = options;
|
||||
if (this.task.state) {
|
||||
this.task.state[options.key] = { ...options };
|
||||
this.task.state[key] = value;
|
||||
} else {
|
||||
this.task.state = { [options.key]: options };
|
||||
this.task.state = { [key]: value };
|
||||
}
|
||||
await this.storage.saveCheckpoint?.({
|
||||
taskId: this.task.taskId,
|
||||
|
||||
@@ -25,6 +25,7 @@ export type {
|
||||
TaskStoreEmitOptions,
|
||||
TaskStoreListEventsOptions,
|
||||
TaskStoreShutDownTaskOptions,
|
||||
TaskStoreStateOptions,
|
||||
SerializedTask,
|
||||
SerializedTaskEvent,
|
||||
TaskStatus,
|
||||
|
||||
@@ -113,6 +113,11 @@ export type TaskStoreEmitOptions<TBody = JsonObject> = {
|
||||
body: TBody;
|
||||
};
|
||||
|
||||
/**
|
||||
* TaskStoreStateOptions
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type TaskStoreStateOptions = {
|
||||
taskId: string;
|
||||
state?: TaskState;
|
||||
|
||||
@@ -30,6 +30,10 @@ export type ActionContext<
|
||||
secrets?: TaskSecrets;
|
||||
workspacePath: string;
|
||||
input: TActionInput;
|
||||
checkpoint?<U extends JsonValue>(
|
||||
key: string,
|
||||
fn: () => Promise<U>,
|
||||
): Promise<U>;
|
||||
output(
|
||||
name: keyof TActionOutput,
|
||||
value: TActionOutput[keyof TActionOutput],
|
||||
@@ -60,6 +64,19 @@ export function addFiles(options: {
|
||||
logger?: Logger | undefined;
|
||||
}): Promise<void>;
|
||||
|
||||
// @public
|
||||
export type CheckpointRecord =
|
||||
| {
|
||||
key: string;
|
||||
status: 'success';
|
||||
value: JsonValue;
|
||||
}
|
||||
| {
|
||||
key: string;
|
||||
status: 'failed';
|
||||
reason: string;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export function cloneRepo(options: {
|
||||
url: string;
|
||||
@@ -345,6 +362,13 @@ export interface TaskContext {
|
||||
// (undocumented)
|
||||
emitLog(message: string, logMetadata?: JsonObject): Promise<void>;
|
||||
// (undocumented)
|
||||
getCheckpoints?(): Promise<
|
||||
| {
|
||||
state: TaskState;
|
||||
}
|
||||
| undefined
|
||||
>;
|
||||
// (undocumented)
|
||||
getWorkspaceName(): Promise<string>;
|
||||
// (undocumented)
|
||||
isDryRun?: boolean;
|
||||
@@ -352,6 +376,10 @@ export interface TaskContext {
|
||||
secrets?: TaskSecrets;
|
||||
// (undocumented)
|
||||
spec: TaskSpec;
|
||||
// (undocumented)
|
||||
state?: TaskState;
|
||||
// (undocumented)
|
||||
updateCheckpoint?(options: CheckpointRecord): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
@@ -362,6 +390,19 @@ export type TaskSecrets = Record<string, string> & {
|
||||
backstageToken?: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type TaskState = {
|
||||
[key: string]:
|
||||
| {
|
||||
status: 'failed';
|
||||
reason: string;
|
||||
}
|
||||
| {
|
||||
status: 'success';
|
||||
value: JsonValue;
|
||||
};
|
||||
};
|
||||
|
||||
// @public
|
||||
export type TaskStatus =
|
||||
| 'cancelled'
|
||||
|
||||
@@ -35,7 +35,7 @@ export type ActionContext<
|
||||
secrets?: TaskSecrets;
|
||||
workspacePath: string;
|
||||
input: TActionInput;
|
||||
checkpoint<U extends JsonValue>(
|
||||
checkpoint?<U extends JsonValue>(
|
||||
key: string,
|
||||
fn: () => Promise<U>,
|
||||
): Promise<U>;
|
||||
|
||||
@@ -27,7 +27,7 @@ export type TaskSecrets = Record<string, string> & {
|
||||
};
|
||||
|
||||
/**
|
||||
* The record passed to {@link TaskBroker.updateCheckpoint?}
|
||||
* The record passed to TaskBroker for updating a checkpoint.
|
||||
* Parameters to store the result of the executed checkpoint
|
||||
*
|
||||
* @public
|
||||
@@ -45,7 +45,7 @@ export type CheckpointRecord =
|
||||
};
|
||||
|
||||
/**
|
||||
* TaskState
|
||||
* The state of all task's checkpoints
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user