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.
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:
Copy
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 }}
Copy
// 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.
Very secure. Every request includes a cryptographic signature that you must verify. This ensures only legitimate Schedo requests can trigger your endpoints.
Yes! The webhook approach works with both Node.js runtime and Edge Runtime functions in Next.js.
Most platforms have execution time limits (10s for Hobby, 60s for Pro on Vercel). For longer tasks, consider breaking them into smaller chunks or using a queue system.
Return appropriate HTTP status codes from your endpoint. Schedo will automatically retry failed requests based on your retry configuration.
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.