Skip to content

Commit

Permalink
🐛 Bug monitor length (#1005)
Browse files Browse the repository at this point in the history
* 🐛 monitor length

* 🐛 monitor length

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
thibaultleouay and autofix-ci[bot] authored Sep 16, 2024
1 parent 05c141f commit 96bbc4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 14 additions & 4 deletions apps/web/src/app/api/checker/cron/_cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,32 @@ export const cron = async ({

console.log(`Start cron for ${periodicity}`);

const monitors = z.array(selectMonitorSchema).parse(result);
const monitors = z.array(selectMonitorSchema).safeParse(result);
const allResult = [];
if (!monitors.success) {
console.error(`Error while fetching the monitors ${monitors.error.errors}`);
throw new Error("Error while fetching the monitors");
}

for (const row of monitors) {
for (const row of monitors.data) {
const selectedRegions = row.regions.length > 0 ? row.regions : ["ams"];

const result = await db
.select()
.from(monitorStatusTable)
.where(eq(monitorStatusTable.monitorId, row.id))
.all();
const monitorStatus = z.array(selectMonitorStatusSchema).parse(result);
const monitorStatus = z.array(selectMonitorStatusSchema).safeParse(result);
if (!monitorStatus.success) {
console.error(
`Error while fetching the monitor status ${monitorStatus.error.errors}`,
);
continue;
}

for (const region of selectedRegions) {
const status =
monitorStatus.find((m) => region === m.region)?.status || "active";
monitorStatus.data.find((m) => region === m.region)?.status || "active";
const response = createCronTask({
row,
timestamp,
Expand Down
5 changes: 4 additions & 1 deletion packages/db/src/schema/monitors/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ const headersSchema = z
.optional();

export const insertMonitorSchema = createInsertSchema(monitor, {
name: z.string().min(1, "Name must be at least 1 character long"),
name: z
.string()
.min(1, "Name must be at least 1 character long")
.max(255, "Name must be at most 255 characters long"),
periodicity: monitorPeriodicitySchema.default("10m"),
status: monitorStatusSchema.default("active"),
regions: z.array(monitorRegionSchema).default([]).optional(),
Expand Down

0 comments on commit 96bbc4b

Please sign in to comment.