Run reliable scheduled tasks on Next.js with webhook-based cron jobs. Perfect for serverless applications with built-in signature verification and monitoring.
Schedo integrates seamlessly with Next.js through webhook-based scheduling. Instead of traditional cron jobs that require persistent processes, Schedo sends HTTP requests to your Next.js API routes at scheduled times.
Schedo webhooks work with any hosting platform that supports Next.js API routes. For optimal performance and reliability, we recommend Sherpa.sh - our preferred Next.js hosting partner with container-first architecture and no function timeouts.Here are configuration examples for popular platforms:
Serverless Functions: Most platforms limit execution time (typically 10-60 seconds)
Container Deployments: No execution time limits, better for long-running tasks
Static Hosting: Ensure API routes are properly configured and deployed
Recommended: Sherpa.sh offers the best experience for Schedo.dev integration with container-based deployments, no timeout limits, and enhanced monitoring. Schedo.dev actively develops new features with Sherpa.sh compatibility first. Learn more about Sherpa.sh integration.
For enhanced security, you can restrict your cron endpoints to only accept requests from Schedo.dev servers. This prevents unauthorized access to your webhook endpoints.
IP allowlisting is available as an enterprise feature. Contact our support team at support@schedo.dev to enable IP allowlisting for your account and receive the current list of Schedo.dev IP addresses.
Once enabled, you can implement IP filtering in your Next.js application:
const ALLOWED_IPS = [ // IPs will be provided by Schedo.dev support team '10.0.0.1', '10.0.0.2', // Add more IPs as provided];export async function POST(req: NextRequest) { const clientIP = req.ip ?? req.headers.get('x-forwarded-for') ?? '127.0.0.1'; if (!ALLOWED_IPS.includes(clientIP)) { console.warn(`Blocked request from unauthorized IP: ${clientIP}`); return NextResponse.json({ error: "Unauthorized" }, { status: 403 }); } // Continue with signature verification and processing...}
Benefits of IP allowlisting:
Additional Security Layer: Prevents direct access to your webhook endpoints
Compliance: Meets security requirements for sensitive applications
Audit Trail: Clear logging of blocked unauthorized requests
Peace of Mind: Ensures only Schedo.dev can trigger your scheduled tasks
Schedo.dev provides comprehensive monitoring and visibility for your Next.js cron jobs directly in the dashboard. This gives you complete insight into your webhook executions without needing to implement custom monitoring solutions.
// Make sure to stringify the body exactly as receivedconst bodyString = JSON.stringify(body);const isValid = verifier.verifyBytesSignature( Buffer.from(bodyString), signature);
// For long-running tasks, break them into smaller chunksasync function processLargeDataset(data: any[]) { const batchSize = 100; for (let i = 0; i < data.length; i += batchSize) { const batch = data.slice(i, i + batchSize); await processBatch(batch); // Prevent timeout if (i % 500 === 0) { await new Promise(resolve => setTimeout(resolve, 100)); } }}
// Stream large data instead of loading everything into memoryimport { Readable } from 'stream';async function processLargeFile() { const stream = createReadStream('large-file.json'); for await (const chunk of stream) { await processChunk(chunk); }}
# Remove this from .github/workflows/cron.ymlname: Scheduled Taskon: schedule: - cron: '0 9 * * *'jobs: run: runs-on: ubuntu-latest steps: - name: Trigger endpoint run: curl -X POST ${{ secrets.WEBHOOK_URL }}
// Add this to your Next.js app insteadexport async function POST(req: NextRequest) { // Your scheduled task logic here await runScheduledTask(); return NextResponse.json({ success: true });}
No! That’s the beauty of webhook-based scheduling. Your Next.js functions only run when Schedo triggers them, making it perfect for serverless architectures.
How secure are the webhook requests?
Very secure. Every request includes a cryptographic signature that you must verify. This ensures only legitimate Schedo requests can trigger your endpoints.
Can I use this with Next.js Edge Functions?
Yes! The webhook approach works with both Node.js runtime and Edge Runtime functions in Next.js.
What about Next.js function execution limits?
Most serverless platforms have execution time limits (typically 10-60 seconds). For longer tasks, consider breaking them into smaller chunks or using a queue system.
How do I handle failures and retries?
Return appropriate HTTP status codes from your endpoint. Schedo will automatically retry failed requests based on your retry configuration.
Can I schedule multiple different tasks?
Yes! You can create multiple webhook jobs pointing to different endpoints, or use a single endpoint with custom payload data to determine which task to run.