Readme
Use this val to monitor your schedule jobs for any issues and report them directly to Sentry Crons.
- After forking, find the DSN for your Sentry project by going to Settings > Projects > Select your project >Settings > Client Keys (DSN).
- Add your DSN to as a
SENTRY_DSN
in your val.town environment variables. - Change the
monitorConfig.schedule.value
Crontab expression to match your job run. - Replace the
run()
function with your scheduled function. - Alter any other monitor config properties to better fit your scheduled function. Learn more.
This val will automatically create and set up a Cron monitor in Sentry, and report all of your runs as check-ins. If your job ever misses a run or fails, Sentry will notify you.
Any errors that occur in your scheduled function will be reported directly into Sentry:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as Sentry from "https://deno.land/x/sentry/index.mjs";
Sentry.init({
dsn: Deno.env.get("SENTRY_DSN"),
});
const monitorSlug = "sentry-val-town-example";
const monitorConfig = {
schedule: {
type: "crontab",
value: "15 * * * *",
},
checkinMargin: 2,
maxRuntime: 10,
timezone: "UTC",
};
// implement your cron job run here
const run = async (interval: Interval) => {
const delay = ms => new Promise(res => setTimeout(res, ms));
console.log(`Last run at ${interval.lastRunAt}`);
console.log("Starting 2s simulated job...");
await delay(2000);
console.log("Done");
// throw new Error("Any errors will be reported to Sentry");
};
export default async function(interval: Interval) {
try {
await Sentry.withMonitor(
monitorSlug,
() => run(interval),
monitorConfig,
);
} catch (err) {
Sentry.captureException(err);
throw err;
} finally {
await Sentry.flush(1000);
}
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.