-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdelete-workflow.ts
More file actions
42 lines (32 loc) · 1.09 KB
/
delete-workflow.ts
File metadata and controls
42 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { WorkflowEntrypoint, WorkflowEvent, WorkflowStep } from 'cloudflare:workers';
import { parseTtlMsInput, clampTtlMs } from './ttl';
type Params = {
projectID: string;
ttlMs?: number;
};
type Env = {
INTEGRATION_TOKEN: string;
};
export class DeleteDbWorkflow extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep): Promise<void> {
const { projectID, ttlMs } = event.payload;
if (!projectID) {
throw new Error('No projectID provided.');
}
const rawTtlMs = parseTtlMsInput(ttlMs);
const effectiveTtlMs = clampTtlMs(rawTtlMs);
const effectiveTtlSeconds = Math.ceil(effectiveTtlMs / 1000);
await step.sleep(`wait ${effectiveTtlSeconds} seconds`, `${effectiveTtlSeconds} seconds`);
const res = await fetch(`https://api.prisma.io/v1/projects/${projectID}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.env.INTEGRATION_TOKEN}`,
},
});
if (!res.ok) {
throw new Error(`Failed to delete project: ${res.statusText}`);
}
}
}
export default DeleteDbWorkflow;