diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/MemoryTaskStore.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/MemoryTaskStore.test.ts deleted file mode 100644 index c5522cb38a..0000000000 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/MemoryTaskStore.test.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2021 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -describe('MemoryDatabase', () => { - it('should be tested', async () => { - expect(1).toBe(2); - }); -}); diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/MemoryTaskStore.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/MemoryTaskStore.ts deleted file mode 100644 index e181edf524..0000000000 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/MemoryTaskStore.ts +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2021 Spotify AB - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - DbTaskRow, - DbTaskEventRow, - Status, - TaskSpec, - TaskStore, - TaskStoreGetEventsOptions, - TaskStoreEmitOptions, -} from './types'; -import { v4 as uuid } from 'uuid'; - -export class MemoryTaskStore implements TaskStore { - private readonly store = new Map(); - private readonly events = new Array(); - - async emit({ taskId, runId, body, type }: TaskStoreEmitOptions) { - this.events.push({ - id: this.events.length, - taskId, - runId, - body, - type, - createdAt: new Date().toISOString(), - }); - } - - async getEvents({ - taskId, - after, - }: TaskStoreGetEventsOptions): Promise<{ events: DbTaskEventRow[] }> { - const events = this.events.filter(event => { - if (event.taskId !== taskId) { - return false; - } - if (after !== undefined) { - if (event.id <= after) { - return false; - } - } - return true; - }); - return { events }; - } - - async heartbeat(runId: string): Promise { - let task: DbTaskRow | undefined; - - for (const t of this.store.values()) { - if (t.runId === runId) { - task = t; - } - } - - if (!task) { - throw new Error('No task with matching runId found'); - } - - this.store.set(task.id, { - ...task, - lastHeartbeat: new Date().toISOString(), - }); - } - - async claimTask(): Promise { - for (const t of this.store.values()) { - if (t.status === 'open') { - const task: DbTaskRow = { - ...t, - status: 'processing', - runId: uuid(), - }; - this.store.set(t.id, task); - return task; - } - } - return undefined; - } - - async createTask(spec: TaskSpec): Promise<{ taskId: string }> { - const taskRow = { - id: uuid(), - spec, - status: 'open' as Status, - retryCount: 0, - createdAt: new Date().toISOString(), - }; - this.store.set(taskRow.id, taskRow); - return { taskId: taskRow.id }; - } - - async get(taskId: string): Promise { - const task = this.store.get(taskId); - if (task) { - return task; - } - throw new Error(`could not found task ${taskId}`); - } - - 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.id, { ...task, status }); - } -} diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/index.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/index.ts index 7b6552a3e0..c85135426e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/index.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -export { MemoryTaskStore } from './MemoryTaskStore'; export { DatabaseTaskStore } from './DatabaseTaskStore'; export { StorageTaskBroker } from './StorageTaskBroker'; export { TaskWorker } from './TaskWorker';