2022-09-16 22:51:19 +00:00
|
|
|
import { CloudRunnerSystem } from '../cloud-runner/services/cloud-runner-system';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import CloudRunner from '../cloud-runner/cloud-runner';
|
2022-09-16 21:24:23 +00:00
|
|
|
export class SharedWorkspaceLocking {
|
2022-09-16 22:51:19 +00:00
|
|
|
public static async GetLockedWorkspace() {
|
2022-09-16 21:24:23 +00:00
|
|
|
const workspaces = SharedWorkspaceLocking.GetFreeWorkspaces();
|
|
|
|
|
for (const element of workspaces) {
|
2022-09-16 22:51:19 +00:00
|
|
|
if (await SharedWorkspaceLocking.LockWorkspace(element)) {
|
2022-09-16 21:24:23 +00:00
|
|
|
return element;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GetFreeWorkspaces(): string[] {
|
2022-09-17 02:52:50 +00:00
|
|
|
return ['test-workspace'];
|
2022-09-16 21:24:23 +00:00
|
|
|
}
|
|
|
|
|
public static GetAllWorkspaces(): string[] {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2022-09-16 22:51:19 +00:00
|
|
|
public static async LockWorkspace(workspace: string): Promise<boolean> {
|
|
|
|
|
// this job + date
|
|
|
|
|
const file = `_lock_${CloudRunner.buildParameters.buildGuid}_${Date.now()}`;
|
|
|
|
|
fs.writeFileSync(file, '');
|
2022-09-17 03:20:09 +00:00
|
|
|
await CloudRunnerSystem.Run(`aws s3 cp ./${file} s3://game-ci-test-storage/locks/${workspace}`);
|
2022-09-16 22:51:19 +00:00
|
|
|
fs.rmSync(file);
|
|
|
|
|
|
|
|
|
|
return SharedWorkspaceLocking.HasWorkspaceLock(workspace);
|
|
|
|
|
}
|
|
|
|
|
public static async HasWorkspaceLock(workspace: string): Promise<boolean> {
|
|
|
|
|
await CloudRunnerSystem.Run(`aws s3 ls ./game-ci-test-storage/locks/${workspace}`);
|
|
|
|
|
|
2022-09-16 21:24:23 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
|
public static IsWorkspaceLocked(workspace: string) {}
|
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
|
public static CreateLockableWorkspace(workspace: string, locked: boolean = false) {}
|
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
|
|
|
|
public static ReleaseLock(workspace: string) {}
|
|
|
|
|
}
|
2022-09-16 18:48:40 +00:00
|
|
|
|
|
|
|
|
export default SharedWorkspaceLocking;
|