@@ -389,6 +389,8 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
// (undocumented)
|
||||
claimTask(): Promise<SerializedTask_2 | undefined>;
|
||||
// (undocumented)
|
||||
cleanWorkspace({ taskId }: { taskId: string }): Promise<void>;
|
||||
// (undocumented)
|
||||
completeTask(options: {
|
||||
taskId: string;
|
||||
status: TaskStatus_2;
|
||||
@@ -540,6 +542,8 @@ export class TaskManager implements TaskContext_2 {
|
||||
// (undocumented)
|
||||
get cancelSignal(): AbortSignal;
|
||||
// (undocumented)
|
||||
cleanWorkspace?(): Promise<void>;
|
||||
// (undocumented)
|
||||
complete(result: TaskCompletionState_2, metadata?: JsonObject): Promise<void>;
|
||||
// (undocumented)
|
||||
static create(
|
||||
@@ -548,6 +552,7 @@ export class TaskManager implements TaskContext_2 {
|
||||
abortSignal: AbortSignal,
|
||||
logger: Logger,
|
||||
auth?: AuthService,
|
||||
config?: Config,
|
||||
): TaskManager;
|
||||
// (undocumented)
|
||||
get createdBy(): string | undefined;
|
||||
@@ -567,7 +572,9 @@ export class TaskManager implements TaskContext_2 {
|
||||
// (undocumented)
|
||||
getWorkspaceName(): Promise<string>;
|
||||
// (undocumented)
|
||||
rehydrateWorkspace(options: {
|
||||
get isWorkspaceSerializationEnabled(): boolean;
|
||||
// (undocumented)
|
||||
rehydrateWorkspace?(options: {
|
||||
taskId: string;
|
||||
targetPath: string;
|
||||
}): Promise<void>;
|
||||
@@ -606,6 +613,8 @@ export interface TaskStore {
|
||||
// (undocumented)
|
||||
claimTask(): Promise<SerializedTask | undefined>;
|
||||
// (undocumented)
|
||||
cleanWorkspace?({ taskId }: { taskId: string }): Promise<void>;
|
||||
// (undocumented)
|
||||
completeTask(options: {
|
||||
taskId: string;
|
||||
status: TaskStatus;
|
||||
|
||||
+5
@@ -47,6 +47,11 @@ export interface Config {
|
||||
*/
|
||||
EXPERIMENTAL_recoverTasks?: boolean;
|
||||
|
||||
/**
|
||||
* Sets the serialization of the workspace to have an ability to rerun the failed task.
|
||||
*/
|
||||
EXPERIMENTAL_workspaceSerialization?: boolean;
|
||||
|
||||
/**
|
||||
* Every task which is in progress state and having a last heartbeat longer than a specified timeout is going to
|
||||
* be attempted to recover.
|
||||
|
||||
@@ -522,6 +522,12 @@ export class DatabaseTaskStore implements TaskStore {
|
||||
await restoreWorkspace(options.targetPath, result.workspace);
|
||||
}
|
||||
|
||||
async cleanWorkspace({ taskId }: { taskId: string }): Promise<void> {
|
||||
await this.db<RawDbTaskRow>('tasks').where({ id: taskId }).update({
|
||||
workspace: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
async serializeWorkspace(options: {
|
||||
path: string;
|
||||
taskId: string;
|
||||
|
||||
@@ -457,6 +457,7 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
|
||||
throw new Error(`Step ${step.name} has been cancelled.`);
|
||||
}
|
||||
|
||||
await task.cleanWorkspace?.();
|
||||
await stepTrack.markSuccessful();
|
||||
} catch (err) {
|
||||
await taskTrack.markFailed(step, err);
|
||||
|
||||
@@ -64,8 +64,16 @@ export class TaskManager implements TaskContext {
|
||||
abortSignal: AbortSignal,
|
||||
logger: Logger,
|
||||
auth?: AuthService,
|
||||
config?: Config,
|
||||
) {
|
||||
const agent = new TaskManager(task, storage, abortSignal, logger, auth);
|
||||
const agent = new TaskManager(
|
||||
task,
|
||||
storage,
|
||||
abortSignal,
|
||||
logger,
|
||||
auth,
|
||||
config,
|
||||
);
|
||||
agent.startTimeout();
|
||||
return agent;
|
||||
}
|
||||
@@ -77,8 +85,17 @@ export class TaskManager implements TaskContext {
|
||||
private readonly signal: AbortSignal,
|
||||
private readonly logger: Logger,
|
||||
private readonly auth?: AuthService,
|
||||
private readonly config?: Config,
|
||||
) {}
|
||||
|
||||
get isWorkspaceSerializationEnabled(): boolean {
|
||||
return (
|
||||
this.config?.getOptionalBoolean(
|
||||
'scaffolder.EXPERIMENTAL_workspaceSerialization',
|
||||
) ?? false
|
||||
);
|
||||
}
|
||||
|
||||
get spec() {
|
||||
return this.task.spec;
|
||||
}
|
||||
@@ -99,11 +116,13 @@ export class TaskManager implements TaskContext {
|
||||
return this.task.taskId;
|
||||
}
|
||||
|
||||
async rehydrateWorkspace(options: {
|
||||
async rehydrateWorkspace?(options: {
|
||||
taskId: string;
|
||||
targetPath: string;
|
||||
}): Promise<void> {
|
||||
return this.storage.rehydrateWorkspace?.(options);
|
||||
if (this.isWorkspaceSerializationEnabled) {
|
||||
this.storage.rehydrateWorkspace?.(options);
|
||||
}
|
||||
}
|
||||
|
||||
get done() {
|
||||
@@ -152,10 +171,18 @@ export class TaskManager implements TaskContext {
|
||||
}
|
||||
|
||||
async serializeWorkspace?(options: { path: string }): Promise<void> {
|
||||
await this.storage.serializeWorkspace?.({
|
||||
path: options.path,
|
||||
taskId: this.task.taskId,
|
||||
});
|
||||
if (this.isWorkspaceSerializationEnabled) {
|
||||
await this.storage.serializeWorkspace?.({
|
||||
path: options.path,
|
||||
taskId: this.task.taskId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async cleanWorkspace?(): Promise<void> {
|
||||
if (this.isWorkspaceSerializationEnabled) {
|
||||
await this.storage.cleanWorkspace?.({ taskId: this.task.taskId });
|
||||
}
|
||||
}
|
||||
|
||||
async complete(
|
||||
@@ -338,6 +365,7 @@ export class StorageTaskBroker implements TaskBroker {
|
||||
abortController.signal,
|
||||
this.logger,
|
||||
this.auth,
|
||||
this.config,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,6 +217,8 @@ export interface TaskStore {
|
||||
targetPath: string;
|
||||
}): Promise<void>;
|
||||
|
||||
cleanWorkspace?({ taskId }: { taskId: string }): Promise<void>;
|
||||
|
||||
serializeWorkspace?({
|
||||
path,
|
||||
taskId,
|
||||
|
||||
@@ -344,6 +344,8 @@ export interface TaskContext {
|
||||
// (undocumented)
|
||||
cancelSignal: AbortSignal;
|
||||
// (undocumented)
|
||||
cleanWorkspace?(): Promise<void>;
|
||||
// (undocumented)
|
||||
complete(result: TaskCompletionState, metadata?: JsonObject): Promise<void>;
|
||||
// (undocumented)
|
||||
createdBy?: string;
|
||||
|
||||
@@ -143,6 +143,8 @@ export interface TaskContext {
|
||||
|
||||
serializeWorkspace?(options: { path: string }): Promise<void>;
|
||||
|
||||
cleanWorkspace?(): Promise<void>;
|
||||
|
||||
rehydrateWorkspace?(options: {
|
||||
taskId: string;
|
||||
targetPath: string;
|
||||
|
||||
Reference in New Issue
Block a user