import {
SchedoSDK,
ExecutionInterval,
withApiKey,
withBaseURL,
} from "@useschedo/node";
// Initialize the SDK with your API key
const schedo = new SchedoSDK(withApiKey("YOUR_API_KEY"));
// Define a job that runs every day at midnight
try {
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 listener
schedo.start();
// Graceful shutdown
process.on('SIGTERM', () => {
console.log('Shutting down...');
schedo.stop();
process.exit(0);
});