Skip to content

Commit

Permalink
Refactor cron monitor slugs for cleanup and minion-price (#123)
Browse files Browse the repository at this point in the history
This pull request refactors the cron monitor slugs for the cleanup and minion-price functionality. The monitor slugs have been updated to "cleanup" and "minion-price" respectively. This change ensures consistency and improves code readability.
  • Loading branch information
DarthGigi authored May 19, 2024
2 parents 9ce4b18 + 3a09582 commit d49deab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
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

0 comments on commit d49deab

Please sign in to comment.