Signed-off-by: bnechyporenko <bnechyporenko@bol.com>
This commit is contained in:
bnechyporenko
2024-02-19 19:40:38 +01:00
parent 74b0777c53
commit c729e282c5
5 changed files with 52 additions and 10 deletions
-1
View File
@@ -76,7 +76,6 @@
"@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:*",
@@ -199,9 +199,11 @@ describe('DatabaseTaskStore', () => {
await store.saveTaskState({
taskId,
state: {
'repo.create': {
status: 'success',
value: { repoUrl: 'https://github.com/backstage/backstage.git' },
checkpoints: {
'repo.create': {
status: 'success',
value: { repoUrl: 'https://github.com/backstage/backstage.git' },
},
},
},
});
@@ -210,9 +212,11 @@ describe('DatabaseTaskStore', () => {
expect(state).toStrictEqual({
state: {
'repo.create': {
status: 'success',
value: { repoUrl: 'https://github.com/backstage/backstage.git' },
checkpoints: {
'repo.create': {
status: 'success',
value: { repoUrl: 'https://github.com/backstage/backstage.git' },
},
},
},
});
@@ -242,4 +242,31 @@ describe('StorageTaskBroker', () => {
const promise = broker.list({ createdBy: 'user:default/foo' });
await expect(promise).resolves.toEqual({ tasks: [task] });
});
it('should handle checkpoints in task state', async () => {
const broker = new StorageTaskBroker(storage, logger);
await broker.dispatch({
spec: { steps: [] } as unknown as TaskSpec,
createdBy: 'user:default/foo',
});
const taskA = await broker.claim();
await taskA.updateCheckpoint?.({
key: 'repo.create',
status: 'success',
value: 'https://github.com/backstage/backstage.git',
});
expect(await taskA.getTaskState?.()).toEqual({
state: {
checkpoints: {
'repo.create': {
status: 'success',
value: 'https://github.com/backstage/backstage.git',
},
},
},
});
});
});
@@ -31,6 +31,19 @@ import {
import { TaskStore } from './types';
import { readDuration } from './helper';
type TaskState = {
checkpoints: {
[key: string]:
| {
status: 'failed';
reason: string;
}
| {
status: 'success';
value: JsonValue;
};
};
};
/**
* TaskManager
*
@@ -115,9 +128,9 @@ export class TaskManager implements TaskContext {
): Promise<void> {
const { key, ...value } = options;
if (this.task.state) {
this.task.state[key] = value;
(this.task.state as TaskState).checkpoints[key] = value;
} else {
this.task.state = { [key]: value };
this.task.state = { checkpoints: { [key]: value } };
}
await this.storage.saveTaskState?.({
taskId: this.task.taskId,
-1
View File
@@ -41210,7 +41210,6 @@ __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:*"