File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import type { Handler , HandlerEvent , HandlerContext } from "@netlify/functions" ;
2+
3+ /**
4+ * Netlify Background + Scheduled Function - Test scheduled function
5+ *
6+ * This function combines both background and scheduled execution:
7+ * - Can be invoked via HTTP POST (returns 202 immediately, runs in background)
8+ * - Can be triggered on a schedule (runs automatically via cron)
9+ *
10+ * Background functions have a 15-minute timeout (vs 30 seconds for regular functions)
11+ * and return a 202 response immediately while processing continues in the background.
12+ *
13+ * Scheduled: Runs automatically every 30 seconds (configured via export config)
14+ */
15+ export const handler : Handler = async (
16+ event : HandlerEvent ,
17+ context : HandlerContext
18+ ) => {
19+ console . log (
20+ "[test-scheduled] Test message - function executed at" ,
21+ new Date ( ) . toISOString ( )
22+ ) ;
23+
24+ return {
25+ statusCode : 200 ,
26+ body : JSON . stringify ( {
27+ success : true ,
28+ message : "Test scheduled function executed" ,
29+ timestamp : new Date ( ) . toISOString ( ) ,
30+ } ) ,
31+ } ;
32+ } ;
33+
34+ /**
35+ * Netlify function configuration
36+ * - type: 'experimental-background' enables background execution (15 min timeout, returns 202 immediately)
37+ * - schedule: Cron expression for scheduled execution (runs every 30 seconds)
38+ */
39+ export const config = {
40+ type : "experimental-background" as const ,
41+ schedule : "*/30 * * * * *" , // Every 30 seconds (6-field cron with seconds)
42+ } ;
You can’t perform that action at this time.
0 commit comments