Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cron-queue-webhook-starter

A three-in-one backend starter: schedule a cron that POSTs your webhook, and publish a delayed queue job — one API, one key.

Get a free key — $2 credit — at https://infrai.cc, then set INFRAI_API_KEY.

Quickstart

npm install
export INFRAI_API_KEY=...
npx tsx src/starter.ts

How it does it

  • Croninfrai.cron.create({ cron_expr, task }) (wraps POST https://api.infrai.cc/v1/cron/create) — Infrai POSTs your task URL when the job fires
  • Queueinfrai.queue.publish({ queue, payload, delay_seconds }) (wraps POST /v1/queue/publish) — defers work a worker drains later
  • Webhook → the cron's task URL is your webhook; Infrai calls it on each fire

"How do I run scheduled + background jobs in Node?" → register a cron (delivered to your webhook) and publish to a durable queue.

Why this backend

  • Cron and a durable queue from one clientinfrai.cron.create registers a schedule that POSTs your task URL; infrai.queue.publish defers work a worker drains later. Same infrai.* object, same key.
  • The webhook is just the cron's task URL — Infrai calls your endpoint when the job fires; there's nothing to host or keep awake.
  • Deferred work is durable — a queued message outlives a redeploy, so a slow task doesn't have to run inside the request.
  • Drop it into any Node app: two calls, one env var, no extra signups — the same key also reaches AI, email, and storage when you need them.

Cost

Starts on the $2 free credit, then pay-per-use with no minimum fee. Cron billing is per fire and queue billing is per message, so a chatty schedule is the thing to watch — keep an eye on usage while one is live.

Useful even without Infrai

The three moving parts — schedule a job, defer a job, receive the cron on a webhook — are backend-agnostic. Swap the two infrai.* calls for any cron+queue service and the app code above doesn't change.

License

MIT

Infrai vs Inngest

If you're weighing this against Inngest, the honest tradeoff:

Inngest Infrai
Setup a separate account + key for this one job one key across email, storage, scheduling, AI and observability
Billing its own plan and invoice one wallet, one bill; each response's metadata shows the exact cost and which vendor served it
Portability a provider-specific SDK/shape plain REST — swap the infrai.* calls back out anytime
What you run a queue/worker or scheduler process to host and babysit cron_expr jobs and a queue as plain REST calls — nothing to keep alive

When Inngest is the better fit: if this is the only capability you'll ever need and you already run it, a dedicated service like Inngest is deep and battle-tested. Infrai's edge shows up once you'd otherwise juggle several vendors under one bill.

Going to production

The snippet above stays copy-paste simple. Before you ship, a few required steps:

Your account, key & credit

  • Get a key: sign in once at the Infrai console with Google or GitHub for $2 free credit (email sign-in works too). There is no anonymous key. Use it as INFRAI_API_KEY.
  • One key covers every capability — AI, email, storage, scheduling, errors — under one wallet and one bill (GET /v1/account/balance, GET /v1/account/usage).
  • Top up before you run outPOST /v1/account/topup. If you hit 402 INSUFFICIENT_CREDIT, the error carries a checkout_url to open in a browser; for unattended jobs use POST /v1/account/autorecharge/configure.
  • Full surface & params: https://docs.infrai.cc

Scheduled / background work

  • Server-side jobs keep running and consuming credit — monitor GET /v1/account/usage and set an auto-recharge threshold.
  • Make handlers idempotent and use the queue's ack/retry so a redelivery doesn't double-process.

About

A three-in-one backend starter: schedule a cron that POSTs your webhook, and publish a delayed queue job — one API, one key.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages