Skip to content

Commit 07e6038

Browse files
committed
cleanup uptime deps
1 parent 28aa2aa commit 07e6038

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

apps/uptime/src/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export function checkUptime(
331331
siteId: string,
332332
url: string,
333333
attempt = 1,
334-
maxRetries: number = CONFIG.maxRetries
334+
_maxRetries: number = CONFIG.maxRetries
335335
): Promise<ActionResult<UptimeData>> {
336336
return record("uptime.check_uptime", async () => {
337337
try {

apps/uptime/src/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Receiver } from "@upstash/qstash";
2-
import Elysia from "elysia";
3-
import { z } from "zod";
2+
import { Elysia, t } from "elysia";
43
import { checkUptime, lookupSchedule } from "./actions";
54
import { sendUptimeEvent } from "./lib/producer";
65
import {
@@ -85,13 +84,13 @@ const app = new Elysia()
8584
.get("/health", () => ({ status: "ok" }))
8685
.post("/", async ({ headers, body }) => {
8786
try {
88-
const headerSchema = z.object({
89-
"upstash-signature": z.string(),
90-
"x-schedule-id": z.string(),
91-
"x-max-retries": z.string().optional(),
87+
const headerSchema = t.Object({
88+
"upstash-signature": t.String(),
89+
"x-schedule-id": t.String(),
90+
"x-max-retries": t.String().optional(),
9291
});
9392

94-
const parsed = headerSchema.safeParse(headers);
93+
const parsed = headerSchema.parse(headers);
9594
if (!parsed.success) {
9695
return new Response("Missing required headers", { status: 400 });
9796
}

apps/uptime/src/lib/producer.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type ProducerConfig = {
1616
class UptimeProducer {
1717
private producer: Producer | null = null;
1818
private connected = false;
19-
private config: ProducerConfig;
19+
private readonly config: ProducerConfig;
2020

2121
constructor(config: ProducerConfig) {
2222
this.config = config;
@@ -49,7 +49,7 @@ class UptimeProducer {
4949
this.producer = kafka.producer({
5050
maxInFlightRequests: 1,
5151
idempotent: true,
52-
transactionTimeout: 30000,
52+
transactionTimeout: 30_000,
5353
});
5454

5555
await this.producer.connect();
@@ -64,7 +64,7 @@ class UptimeProducer {
6464

6565
async send(topic: string, event: unknown, key?: string): Promise<void> {
6666
try {
67-
if (!(await this.connect()) || !this.producer) {
67+
if (!((await this.connect()) && this.producer)) {
6868
console.error("Failed to connect to Redpanda, event not sent");
6969
return;
7070
}
@@ -113,12 +113,8 @@ function getDefaultProducer(): UptimeProducer {
113113
return defaultProducer;
114114
}
115115

116-
export const sendUptimeEvent = (
117-
event: unknown,
118-
key?: string
119-
): Promise<void> => {
120-
return getDefaultProducer().send("analytics-uptime-checks", event, key);
121-
};
116+
export const sendUptimeEvent = (event: unknown, key?: string): Promise<void> =>
117+
getDefaultProducer().send("analytics-uptime-checks", event, key);
122118

123119
// Graceful shutdown
124120
process.on("SIGTERM", async () => {
@@ -132,4 +128,3 @@ process.on("SIGINT", async () => {
132128
await defaultProducer.disconnect();
133129
}
134130
});
135-

0 commit comments

Comments
 (0)