Create inital class structure

This commit is contained in:
Johan Haals
2021-01-20 17:18:07 +01:00
parent 9587193208
commit 21e18aced4
5 changed files with 143 additions and 0 deletions
@@ -0,0 +1,35 @@
/*
* 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 { Task, Status } from './types';
export class Database {
private readonly store = new Map<string, Task>();
get(taskId: string) {
return this.store.get(taskId);
}
write(task: Task) {
return task;
}
writeStatus(taskId: string, status: Status) {
const task = this.store.get(taskId);
if (task) {
this.store.set(taskId, { ...task, status });
}
}
}
@@ -0,0 +1,15 @@
/*
* 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.
*/
@@ -0,0 +1,34 @@
/*
* 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 { Status, ClaimResponse } from './types';
import { Database } from './Database';
export class TaskWorker {
static async fromConfig() {}
constructor(private readonly database: Database) {}
claim(): Promise<ClaimResponse> {
return Promise.resolve(undefined);
}
setStatus(taskId: string, status: Status) {
this.database.writeStatus(taskId, status);
}
heartbeat(runId: number) {}
}
@@ -0,0 +1,29 @@
/*
* 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 { Task } from './types';
import { Database } from './Database';
export class taskDispatcher {
static async fromConfig(config: { database: Database }) {}
constructor(private readonly db: Database) {}
dispatch(task: Task): Promise<string> {
this.db.write(task);
return Promise.resolve('uuid');
}
}
@@ -0,0 +1,30 @@
/*
* 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.
*/
export type Status = 'OPEN' | 'PROCESSING' | 'FAILED' | 'CANCELLED';
export type Task = {
taskId: string;
metadata: string;
status: Status;
lastHeartbeat: string;
retryCount: number;
createdAt: string;
};
export type ClaimResponse = {
runId: number;
task: Task;
};