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

Refactor cron monitor slugs for cleanup and minion-price #123

Merged
merged 1 commit into from
May 19, 2024
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
25 changes: 7 additions & 18 deletions src/routes/api/internal/crons/cleanup/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@ import * as Sentry from "@sentry/sveltekit";
import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";

const checkInId = Sentry.captureCheckIn(
{
monitorSlug: "cleanup-cron",
export const GET: RequestHandler = async ({ request }) => {
const checkInId = Sentry.captureCheckIn({
monitorSlug: "cleanup",
status: "in_progress"
},
{
schedule: {
type: "crontab",
value: "0 12 * * *"
},
checkinMargin: 0.2,
maxRuntime: 0.2,
timezone: "Etc/UTC"
}
);
});

export const GET: RequestHandler = async ({ request, fetch }) => {
if (!CRON_SECRET || request.headers.get("Authorization") !== `Bearer ${CRON_SECRET}`) {
Sentry.captureCheckIn({
checkInId,
monitorSlug: "cleanup-cron",
monitorSlug: "cleanup",
status: "error"
});
return json(
Expand All @@ -40,15 +29,15 @@ export const GET: RequestHandler = async ({ request, fetch }) => {
await lucia.deleteExpiredSessions();
Sentry.captureCheckIn({
checkInId,
monitorSlug: "cleanup-cron",
monitorSlug: "cleanup",
status: "ok"
});
return json({ success: true }, { status: 200 });
} catch (e) {
console.error(e);
Sentry.captureCheckIn({
checkInId,
monitorSlug: "cleanup-cron",
monitorSlug: "cleanup",
status: "error"
});
return json({ success: false, error: e }, { status: 500, statusText: "Internal Server Error" });
Expand Down
25 changes: 7 additions & 18 deletions src/routes/api/internal/crons/minionprice/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@ import * as Sentry from "@sentry/sveltekit";
import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types";

const checkInId = Sentry.captureCheckIn(
{
monitorSlug: "minionprice-cron",
export const GET: RequestHandler = async ({ request, fetch }) => {
const checkInId = Sentry.captureCheckIn({
monitorSlug: "minion-price",
status: "in_progress"
},
{
schedule: {
type: "crontab",
value: "0 12 * * *"
},
checkinMargin: 0.2,
maxRuntime: 0.2,
timezone: "Etc/UTC"
}
);
});

export const GET: RequestHandler = async ({ request, fetch }) => {
if (!CRON_SECRET || request.headers.get("Authorization") !== `Bearer ${CRON_SECRET}`) {
Sentry.captureCheckIn({
checkInId,
monitorSlug: "minionprice-cron",
monitorSlug: "minion-price",
status: "error"
});
return json(
Expand All @@ -50,7 +39,7 @@ export const GET: RequestHandler = async ({ request, fetch }) => {

Sentry.captureCheckIn({
checkInId,
monitorSlug: "minionprice-cron",
monitorSlug: "minion-price",
status: "ok"
});

Expand All @@ -59,7 +48,7 @@ export const GET: RequestHandler = async ({ request, fetch }) => {
console.error(e);
Sentry.captureCheckIn({
checkInId,
monitorSlug: "minionprice-cron",
monitorSlug: "minion-price",
status: "error"
});
return json({ success: false, error: JSON.stringify(e) }, { status: 500, statusText: "Internal Server Error" });
Expand Down
Loading