Signed-off-by: bnechyporenko <bnechyporenko@bol.com>
This commit is contained in:
bnechyporenko
2024-02-17 15:08:35 +01:00
parent f0c50af246
commit 562270b6dd
11 changed files with 53 additions and 152 deletions
+1
View File
@@ -76,6 +76,7 @@
"@backstage/repo-tools": "workspace:*",
"@changesets/cli": "^2.14.0",
"@octokit/rest": "^19.0.3",
"@playwright/test": "^1.32.3",
"@spotify/eslint-plugin": "^14.1.3",
"@spotify/prettier-config": "^14.0.0",
"@techdocs/cli": "workspace:*",
+6 -65
View File
@@ -360,17 +360,7 @@ export interface CurrentClaimedTask {
createdBy?: string;
secrets?: TaskSecrets_2;
spec: TaskSpec;
state?: {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
};
state?: JsonObject;
taskId: string;
}
@@ -411,15 +401,7 @@ export class DatabaseTaskStore implements TaskStore {
// (undocumented)
getTaskState({ taskId }: { taskId: string }): Promise<
| {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
state: JsonObject;
}
| undefined
>;
@@ -445,22 +427,7 @@ export class DatabaseTaskStore implements TaskStore {
ids: string[];
}>;
// (undocumented)
saveTaskState(options: {
taskId: string;
state?:
| {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
}
| undefined;
}): Promise<void>;
saveTaskState(options: { taskId: string; state?: JsonObject }): Promise<void>;
// (undocumented)
shutdownTask(options: TaskStoreShutDownTaskOptions): Promise<void>;
}
@@ -565,15 +532,7 @@ export class TaskManager implements TaskContext_2 {
// (undocumented)
getTaskState?(): Promise<
| {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
state?: JsonObject;
}
| undefined
>;
@@ -628,15 +587,7 @@ export interface TaskStore {
// (undocumented)
getTaskState?({ taskId }: { taskId: string }): Promise<
| {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
state: JsonObject;
}
| undefined
>;
@@ -663,17 +614,7 @@ export interface TaskStore {
// (undocumented)
saveTaskState?(options: {
taskId: string;
state?: {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
};
state?: JsonObject;
}): Promise<void>;
// (undocumented)
shutdownTask?(options: TaskStoreShutDownTaskOptions): Promise<void>;
@@ -209,9 +209,11 @@ describe('DatabaseTaskStore', () => {
const state = await store.getTaskState({ taskId });
expect(state).toStrictEqual({
'repo.create': {
status: 'success',
value: { repoUrl: 'https://github.com/backstage/backstage.git' },
state: {
'repo.create': {
status: 'success',
value: { repoUrl: 'https://github.com/backstage/backstage.git' },
},
},
});
});
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { JsonObject, JsonValue } from '@backstage/types';
import { JsonObject } from '@backstage/types';
import {
PluginDatabaseManager,
resolvePackagePath,
@@ -397,42 +397,19 @@ export class DatabaseTaskStore implements TaskStore {
async getTaskState({ taskId }: { taskId: string }): Promise<
| {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
state: JsonObject;
}
| undefined
> {
const [result] = await this.db<RawDbTaskRow>('tasks')
.where({ id: taskId })
.select('state');
return result.state
? (JSON.parse(result.state) as unknown as {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
})
: undefined;
return result.state ? { state: JSON.parse(result.state) } : undefined;
}
async saveTaskState(options: {
taskId: string;
state?:
| {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
}
| undefined;
state?: JsonObject;
}): Promise<void> {
if (options.state) {
const serializedState = JSON.stringify(options.state);
@@ -580,23 +580,27 @@ describe('NunjucksWorkflowRunner', () => {
}),
getTaskState: (): Promise<
| {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
state: {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
};
}
| undefined
> => {
return Promise.resolve({
['v1.task.checkpoint.key1']: {
status: 'success',
value: 'initial',
},
['v1.task.checkpoint.key2']: {
status: 'failed',
reason: 'fatal error',
state: {
['v1.task.checkpoint.key1']: {
status: 'success',
value: 'initial',
},
['v1.task.checkpoint.key2']: {
status: 'failed',
reason: 'fatal error',
},
},
});
},
@@ -79,6 +79,18 @@ type TemplateContext = {
each?: JsonValue;
};
type TaskState = {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
};
const isValidTaskSpec = (taskSpec: TaskSpec): taskSpec is TaskSpecV1beta3 => {
return taskSpec.apiVersion === 'scaffolder.backstage.io/v1beta3';
};
@@ -356,7 +368,7 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
try {
let prevValue: U | undefined;
if (prevTaskState) {
const prevState = prevTaskState[key];
const prevState = (prevTaskState.state as TaskState)?.[key];
if (prevState && prevState.status === 'success') {
prevValue = prevState.value as U;
}
@@ -93,12 +93,7 @@ export class TaskManager implements TaskContext {
async getTaskState?(): Promise<
| {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
state?: JsonObject;
}
| undefined
> {
@@ -186,14 +181,7 @@ export interface CurrentClaimedTask {
/**
* The state of checkpoints of the task.
*/
state?: {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
};
state?: JsonObject;
/**
* The creator of the task.
*/
@@ -196,26 +196,14 @@ export interface TaskStore {
getTaskState?({ taskId }: { taskId: string }): Promise<
| {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
state: JsonObject;
}
| undefined
>;
saveTaskState?(options: {
taskId: string;
state?: {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
};
state?: JsonObject;
}): Promise<void>;
listEvents(
+1 -9
View File
@@ -351,15 +351,7 @@ export interface TaskContext {
// (undocumented)
getTaskState?(): Promise<
| {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
state?: JsonObject;
}
| undefined
>;
+1 -6
View File
@@ -128,12 +128,7 @@ export interface TaskContext {
getTaskState?(): Promise<
| {
[key: string]:
| { status: 'failed'; reason: string }
| {
status: 'success';
value: JsonValue;
};
state?: JsonObject;
}
| undefined
>;
+1
View File
@@ -41210,6 +41210,7 @@ __metadata:
"@changesets/cli": ^2.14.0
"@manypkg/get-packages": ^1.1.3
"@octokit/rest": ^19.0.3
"@playwright/test": ^1.32.3
"@spotify/eslint-plugin": ^14.1.3
"@spotify/prettier-config": ^14.0.0
"@techdocs/cli": "workspace:*"