Create a new file called jobs.ts (or jobs.js if you’re not using TypeScript):
Copy
import { SchedoSDK, ExecutionInterval, withApiKey, withBaseURL,} from "@useschedo/node";// Initialize the SDK with your API keyconst schedo = new SchedoSDK(withApiKey("YOUR_API_KEY"));// Define a job that runs every day at midnighttry { await schedo.defineJob( "error_handling_example", ExecutionInterval.Daily, async (ctx) => { // This job might fail if (Math.random() > 0.5) { throw new Error("Random failure"); } return { success: true }; }, withTimeout(5) // Set a 5-second timeout );} catch (error) { console.error("Failed to define job:", error);}// Start the job listenerschedo.start();// Graceful shutdownprocess.on('SIGTERM', () => { console.log('Shutting down...'); schedo.stop(); process.exit(0);});