Menu

1 / 2

Our lock lived for three hours, our schedule fired every fifteen minutes, and every one of those skipped runs was recorded as a success

DEV Community: redis·Daniel Pertu·about 17 hours ago
#Ozhazey3
#devtoredis#devto#dev#fullscreen#lock
Reading 0:00
15s threshold

Munchable is a barcode scanner for people with digestive conditions. Behind the app there are scheduled jobs, and two different things run them: Vercel Cron hitting a route, and a CLI a person runs in a terminal for the bulk data passes. One of those jobs announces changed pages like the recipe index to search engines every hour; another settles contributor rewards once a month.

They share one guard, withCronLock(name, fn) , which is a Redis key under cron:<name> taken with NX and a TTL. Nothing surprising. The interesting part is what that TTL used to be.

The reasonable version that was wrong

It used to be the job's whole worst-case runtime: three hours for the scheduled runner, six from the CLI. The reasoning writes itself. The lock has to outlive the run, otherwise a second runner starts while the first is still going.

That reasoning is correct.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.