How to Run Cron Jobs in Deno Without a Server Using Deno Deploy and Webhooks

Cron jobs are vital for running background tasks at scheduled intervals. While traditional methods involve servers or managed services, Deno Deploy provides a free, serverless, and modern way to achieve this using webhooks and scheduled triggers from external services like GitHub Actions or Upstash. Why Deno Deploy? Zero configuration serverless functions Support for TypeScript out of the box Free tier with edge deployment How It Works Deno Deploy doesn’t have native scheduled triggers (yet), but you can still implement cron behavior by: Deploying a Deno endpoint Using GitHub Actions or Upstash Scheduler to ping it on a schedule Step 1: Set Up a Deno Project // main.ts import { serve } from "https://deno.land/std/http/server.ts"; serve(async (req: Request) => { const url = new URL(req.url); if (url.pathname === "/run-cron") { // Perform your task here console.log("Cron job triggered:", new Date().toISOString()); // Example: Fetching and cleaning up data const data = await fetch("https://your-api.com/clean"); const result = await data.text(); return new Response(`Cron ran: ${result}`); } return new Response("OK"); }); Step 2: Deploy to Deno Deploy Push your code to a GitHub repository, then visit deno.com/deploy to link your GitHub account and deploy your project. You'll get a public URL like: https://your-cron.deno.dev/run-cron Step 3: Use GitHub Actions as the Scheduler Add this GitHub Actions workflow in your repo: # .github/workflows/schedule.yml name: Trigger Deno Cron on: schedule: - cron: "*/15 * * * *" # every 15 minutes workflow_dispatch: jobs: ping-cron: runs-on: ubuntu-latest steps: - name: Curl to Deno run: curl -X GET https://your-cron.deno.dev/run-cron Push to GitHub, and the cron will start triggering your endpoint. Pros and Cons ✅ Pros Zero-cost setup using Deno and GitHub No infrastructure to manage Easy to deploy and maintain ⚠️ Cons Depends on an external scheduler (e.g., GitHub Actions) No native time-based triggers inside Deno Deploy Limited logging/debugging from GitHub side

Apr 22, 2025 - 02:47
 0
How to Run Cron Jobs in Deno Without a Server Using Deno Deploy and Webhooks

Cron jobs are vital for running background tasks at scheduled intervals. While traditional methods involve servers or managed services, Deno Deploy provides a free, serverless, and modern way to achieve this using webhooks and scheduled triggers from external services like GitHub Actions or Upstash.

Why Deno Deploy?

  • Zero configuration serverless functions
  • Support for TypeScript out of the box
  • Free tier with edge deployment

How It Works

Deno Deploy doesn’t have native scheduled triggers (yet), but you can still implement cron behavior by:

  1. Deploying a Deno endpoint
  2. Using GitHub Actions or Upstash Scheduler to ping it on a schedule

Step 1: Set Up a Deno Project

// main.ts
import { serve } from "https://deno.land/std/http/server.ts";

serve(async (req: Request) => {
  const url = new URL(req.url);

  if (url.pathname === "/run-cron") {
    // Perform your task here
    console.log("Cron job triggered:", new Date().toISOString());

    // Example: Fetching and cleaning up data
    const data = await fetch("https://your-api.com/clean");
    const result = await data.text();

    return new Response(`Cron ran: ${result}`);
  }

  return new Response("OK");
});

Step 2: Deploy to Deno Deploy

Push your code to a GitHub repository, then visit deno.com/deploy to link your GitHub account and deploy your project. You'll get a public URL like:

https://your-cron.deno.dev/run-cron

Step 3: Use GitHub Actions as the Scheduler

Add this GitHub Actions workflow in your repo:

# .github/workflows/schedule.yml
name: Trigger Deno Cron

on:
  schedule:
    - cron: "*/15 * * * *"  # every 15 minutes
  workflow_dispatch:

jobs:
  ping-cron:
    runs-on: ubuntu-latest
    steps:
      - name: Curl to Deno
        run: curl -X GET https://your-cron.deno.dev/run-cron

Push to GitHub, and the cron will start triggering your endpoint.

Pros and Cons

✅ Pros

  • Zero-cost setup using Deno and GitHub
  • No infrastructure to manage
  • Easy to deploy and maintain

⚠️ Cons

  • Depends on an external scheduler (e.g., GitHub Actions)
  • No native time-based triggers inside Deno Deploy
  • Limited logging/debugging from GitHub side