Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix up handler type #3282

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/jobs/lib/routes/postIdle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ const handler = async (req: EndpointRequest<PostIdle>, res: EndpointResponse<Pos
try {
logger.info(`[runner ${req.body.runnerId}]: idle for ${req.body.idleTimeMs}ms. Suspending...`);
await suspendRunner(req.body.runnerId);
return res.status(200).json({ status: 'ok' });
res.status(200).json({ status: 'ok' });
return;
} catch (err) {
return res.status(500).json({ error: { code: 'idle_failed', message: err instanceof Error ? err.message : 'failed to suspend runner' } });
res.status(500).json({ error: { code: 'idle_failed', message: err instanceof Error ? err.message : 'failed to suspend runner' } });
return;
}
};

Expand Down
6 changes: 4 additions & 2 deletions packages/jobs/lib/routes/runners/postIdle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ const handler = async (req: EndpointRequest<PostIdle>, res: EndpointResponse<Pos
if (idle.isErr()) {
throw idle.error;
}
return res.status(200).json({ status: 'ok' });
res.status(200).json({ status: 'ok' });
return;
} catch (err) {
return res.status(500).json({ error: { code: 'idle_failed', message: err instanceof Error ? err.message : 'failed to idle runner' } });
res.status(500).json({ error: { code: 'idle_failed', message: err instanceof Error ? err.message : 'failed to idle runner' } });
return;
}
};

Expand Down
6 changes: 4 additions & 2 deletions packages/jobs/lib/routes/runners/postRegister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ const handler = async (req: EndpointRequest<PostRegister>, res: EndpointResponse
if (register.isErr()) {
throw register.error;
}
return res.status(200).json({ status: 'ok' });
res.status(200).json({ status: 'ok' });
return;
} catch (err) {
return res.status(500).json({ error: { code: 'register_failed', message: err instanceof Error ? err.message : 'failed to register runner' } });
res.status(500).json({ error: { code: 'register_failed', message: err instanceof Error ? err.message : 'failed to register runner' } });
return;
}
};

Expand Down
4 changes: 3 additions & 1 deletion packages/orchestrator/lib/routes/getHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ export const routeHandler: RouteHandler<Health> = {
path,
method,
validate: (_req, _res, next) => next(), // No extra validation needed
handler: (_req, res) => res.status(200).json({ status: 'ok' })
handler: (_req, res) => {
res.status(200).json({ status: 'ok' });
}
};
6 changes: 4 additions & 2 deletions packages/orchestrator/lib/routes/v1/postImmediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ const handler = (scheduler: Scheduler) => {
heartbeatTimeoutSecs: req.body.timeoutSettingsInSecs.heartbeat
});
if (task.isErr()) {
return res.status(500).json({ error: { code: 'immediate_failed', message: task.error.message } });
res.status(500).json({ error: { code: 'immediate_failed', message: task.error.message } });
return;
}
return res.status(200).json({ taskId: task.value.id });
res.status(200).json({ taskId: task.value.id });
return;
};
};

Expand Down
6 changes: 4 additions & 2 deletions packages/orchestrator/lib/routes/v1/postRecurring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ const handler = (scheduler: Scheduler) => {
lastScheduledTaskId: null
});
if (schedule.isErr()) {
return res.status(500).json({ error: { code: 'recurring_failed', message: schedule.error.message } });
res.status(500).json({ error: { code: 'recurring_failed', message: schedule.error.message } });
return;
}
return res.status(200).json({ scheduleId: schedule.value.id });
res.status(200).json({ scheduleId: schedule.value.id });
return;
};
};

Expand Down
9 changes: 6 additions & 3 deletions packages/orchestrator/lib/routes/v1/putRecurring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ const handler = (scheduler: Scheduler) => {
updatedSchedule = await scheduler.setScheduleFrequency({ scheduleName: schedule.name, frequencyMs: schedule.frequencyMs });
}
if (!updatedSchedule) {
return res.status(400).json({ error: { code: 'put_recurring_failed', message: `invalid parameters: ${JSON.stringify(schedule)}` } });
res.status(400).json({ error: { code: 'put_recurring_failed', message: `invalid parameters: ${JSON.stringify(schedule)}` } });
return;
}
if (updatedSchedule.isErr()) {
return res.status(500).json({ error: { code: 'put_recurring_failed', message: updatedSchedule.error.message } });
res.status(500).json({ error: { code: 'put_recurring_failed', message: updatedSchedule.error.message } });
return;
}
return res.status(200).json({ scheduleId: updatedSchedule.value.id });
res.status(200).json({ scheduleId: updatedSchedule.value.id });
return;
};
};

Expand Down
6 changes: 4 additions & 2 deletions packages/orchestrator/lib/routes/v1/schedules/postRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ const handler = (scheduler: Scheduler) => {
scheduleName: req.body.scheduleName
});
if (schedule.isErr()) {
return res.status(500).json({ error: { code: 'recurring_run_failed', message: schedule.error.message } });
res.status(500).json({ error: { code: 'recurring_run_failed', message: schedule.error.message } });
return;
}
return res.status(200).json({ scheduleId: schedule.value.id });
res.status(200).json({ scheduleId: schedule.value.id });
return;
};
};

Expand Down
6 changes: 4 additions & 2 deletions packages/orchestrator/lib/routes/v1/schedules/postSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ const handler = (scheduler: Scheduler) => {
...(names ? { names } : {})
});
if (getSchedules.isErr()) {
return res.status(500).json({ error: { code: 'search_failed', message: getSchedules.error.message } });
res.status(500).json({ error: { code: 'search_failed', message: getSchedules.error.message } });
return;
}
return res.status(200).json(getSchedules.value);
res.status(200).json(getSchedules.value);
return;
};
};

Expand Down
6 changes: 4 additions & 2 deletions packages/orchestrator/lib/routes/v1/tasks/postSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ const handler = (scheduler: Scheduler) => {
...(limit ? { limit } : {})
});
if (getTasks.isErr()) {
return res.status(500).json({ error: { code: 'search_failed', message: getTasks.error.message } });
res.status(500).json({ error: { code: 'search_failed', message: getTasks.error.message } });
return;
}
return res.status(200).json(getTasks.value);
res.status(200).json(getTasks.value);
return;
};
};

Expand Down
4 changes: 3 additions & 1 deletion packages/persist/lib/routes/getHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ export const routeHandler: RouteHandler<Health> = {
path,
method,
validate: (_req, _res, next) => next(),
handler: (_req, res) => res.status(200).json({ status: 'ok' })
handler: (_req, res) => {
res.status(200).json({ status: 'ok' });
}
};
2 changes: 1 addition & 1 deletion packages/utils/lib/express/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Route<E extends Endpoint<any>> {

export interface RouteHandler<E extends Endpoint<any>> extends Route<E> {
validate: (req: EndpointRequest<E>, res: EndpointResponse<E>, next: NextFunction) => void;
handler: (req: EndpointRequest<E>, res: EndpointResponse<E>, next: NextFunction) => void;
handler: (req: EndpointRequest<E>, res: EndpointResponse<E>, next: NextFunction) => void | Promise<void>;
Copy link
Contributor Author

@nalanj nalanj Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍖 You can see down at line 22 that we generally treat it as a promise anyway.

}

export const createRoute = <E extends Endpoint<any>>(server: Express, rh: RouteHandler<E>): void => {
Expand Down
Loading