diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/Database.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/Database.ts index 7c3f343b0f..a3ce732586 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/Database.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/Database.ts @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { DbTaskRow, TaskSpec } from './types'; +import { DbTaskRow, Status, TaskSpec } from './types'; import { v4 as uuid } from 'uuid'; import { DateTime } from 'luxon'; export interface Database { get(taskId: string): Promise; - // updateTask(task: Task): Promise; createTask(task: TaskSpec): Promise; claimTask(): Promise; heartBeat(runId: string): Promise; + setStatus(taskId: string, status: Status): Promise; } export class InMemoryDatabase implements Database { @@ -63,13 +63,15 @@ export class InMemoryDatabase implements Database { } async createTask(spec: TaskSpec): Promise { - return { + const taskRow = { taskId: uuid(), spec, - status: 'OPEN', + status: 'OPEN' as Status, retryCount: 0, createdAt: new Date().toISOString(), }; + this.store.set(taskRow.taskId, taskRow); + return taskRow; } async get(taskId: string): Promise { @@ -80,12 +82,11 @@ export class InMemoryDatabase implements Database { throw new Error(`could not found task ${taskId}`); } - // async updateTask(task: Task): Promise { - // if (!task.taskId) { - // throw new Error('Task must contain id'); - // } - - // this.store.set(task.taskId, task); - // return task; - // } + async setStatus(taskId: string, status: Status): Promise { + const task = this.store.get(taskId); + if (!task) { + throw new Error(`no task found`); + } + this.store.set(task.taskId, { ...task, status }); + } }