-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathperformDeploymentAlerts.server.ts
More file actions
67 lines (60 loc) · 1.87 KB
/
performDeploymentAlerts.server.ts
File metadata and controls
67 lines (60 loc) · 1.87 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { ProjectAlertChannel, ProjectAlertType, WorkerDeployment } from "@trigger.dev/database";
import { alertsWorker } from "~/v3/alertsWorker.server";
import { BaseService } from "../baseService.server";
import { DeliverAlertService } from "./deliverAlert.server";
export class PerformDeploymentAlertsService extends BaseService {
public async call(deploymentId: string) {
const deployment = await this._prisma.workerDeployment.findFirst({
where: { id: deploymentId },
include: {
environment: true,
},
});
if (!deployment) {
return;
}
const alertType =
deployment.status === "DEPLOYED" ? "DEPLOYMENT_SUCCESS" : "DEPLOYMENT_FAILURE";
// Find all the alert channels
const alertChannels = await this._prisma.projectAlertChannel.findMany({
where: {
projectId: deployment.projectId,
alertTypes: {
has: alertType,
},
environmentTypes: {
has: deployment.environment.type,
},
enabled: true,
},
});
for (const alertChannel of alertChannels) {
await this.#createAndSendAlert(alertChannel, deployment, alertType);
}
}
async #createAndSendAlert(
alertChannel: ProjectAlertChannel,
deployment: WorkerDeployment,
alertType: ProjectAlertType
) {
await DeliverAlertService.createAndSendAlert(
{
channelId: alertChannel.id,
channelType: alertChannel.type,
projectId: deployment.projectId,
environmentId: deployment.environmentId,
alertType,
deploymentId: deployment.id,
},
this._prisma
);
}
static async enqueue(deploymentId: string, runAt?: Date) {
return await alertsWorker.enqueue({
id: `performDeploymentAlerts:${deploymentId}`,
job: "v3.performDeploymentAlerts",
payload: { deploymentId },
availableAt: runAt,
});
}
}