A job queue allows apps to schedule jobs to run in the background.
Serverless apps are event-driven, so they only run when called upon. There's no running server that can host a job queue or even run cron-jobs.
But running jobs in background (at specific times) is a need that comes up all the time when building apps.
So I decided to bootstrap a job queue using as little code as possible. My stack:
Basically the app is in Nextjs hosted on Vercel with an endpoint /api/job where users can submit their job.
Here's an example api call to schedule a job:
fetch("https://www.tasklater.io/api/job", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"x-api-key": "API_KEY_GOES_HERE", // replace with your API key
},
body: {
timezone: "America/New_York", // optional (default: "America/New_York")
run_time: 1639015224, // required (Unix timestamp)
url: "https://www.example.com/api/send-delayed-email", // required (endpoint to trigger at run time)
data: { // optional (data passed to your endpoint)
email: "example@gmail.com"
},
}
});
The job gets recorded in airtable and there's one field that makes everything work. The to_run field is a function of whether the run_time is less than or equal to the current time. Seems like Airtable runs these functions every 10 minutes to update the fields.
That means, max 10 minutes after run_time Airtable will update the to_run field to 1.
(Usually delayed jobs are not sensitive to the exact minute, so it's a trade-off I'm willing to take)
The job then enters the "running" view in Airtable. That will run an Airtable automation that runs an Airtable script.
The Airtable script does 2 things:
run_timeYou can currently get an API key at Tasklater.io and get started. This can only do delayed jobs for now, but there's more in the pipeline - here's the roadmap for who's interested.
And btw, it's free! Happy for anyone to test it out 😊
Comments/feedback are much appreciated!
Interesting concept, will try it out soon
Cheers! Hit me up if you have questions ✌️
How is this different from bull queue and agenda js npm packages?
Good question, these are both great libs, although they're not fully compatible with serverless.
You'll need to run a redis or mongo instance on some host and push your jobs to them. To process your jobs, you still need a running server. So you have to write a worker using these libs and host it somewhere.
With Tasklater.io, no need to host anything, just send us your job by specifying its
run_timeand theurlof the serverless function to trigger.