The change check: a cheap run in front of the real one
When you genuinely need a fast schedule and there's no event to wait for, split the routine into a tiny check and a full run that only fires when something actually changed.
Sometimes you really do need five minutes and there's no event to listen for — a launch is live, or a page you don't own is moving fast and only its owner knows when. You can't trigger on an event you don't control. So do the next best thing: don't make the full run cheaper — make most runs not be full runs.
Split the routine into two stages.
Stage one: the check. Read one small thing that tells you whether anything changed — a status field, the last commit hash, a count of open items, a "last updated" timestamp. That's maybe 2,000 tokens and a one-word answer. Compare it to a value you saved last time. If it's the same, log "no change" and stop. If it's different, go on to stage two.
Stage two: the work. Only now does the Bot do the expensive thing — open the page fully, analyze it, write the summary, post the result.
Here's why it works, in numbers. A cheap check costs about $0.004 a run. Say the thing you're watching actually changes about six times a day — so 180 real changes a month, and the rest are "nothing happened":
No check: 8,640 full runs x $0.046 = ~$397
With check: 8,640 checks x $0.004 = ~$35
+ 180 full runs x $0.046 = ~$8
total = ~$43 (about 89% less)
Same five-minute reaction time. Roughly a ninth of the compute. (Six changes a day is an assumption — on a quiet page you save even more, on a busy one less.)
The instruction looks like this:
Every 5 minutes:
CHECK
Open [the page / repo / board]. Read ONLY [the status field / last
commit hash / count of open items / "updated" date]. Compare it to
the value saved in routines/state/<name>.txt. If it is the same, log
"no_change" and stop. Do not open anything else. Do not take a quick
look around.
WORK (only if it changed)
Save the new value to routines/state/<name>.txt, do the actual job,
and post the result in 5 lines or fewer.
Two lines are quietly load-bearing. "Read ONLY ..." keeps the check small — the whole saving comes from the check being cheap, so don't let it read the full page. And "Do not take a quick look around" matters more than it looks: without it, a capable Bot that's already on the page tends to explore, and exploring is a full run. You're paying for discipline here as much as logic. Say it plainly, and the cheap check stays cheap.
Design a change check for one fast routine. Name the single small signal you'd read to detect change, where you'd store last time's value, and the exact "stop if unchanged" wording. Then estimate its monthly cost assuming change happens a realistic number of times per day.
Enjoying the free lessons? Get an email when we publish new courses and updates — no spam, unsubscribe anytime.
Discussion (0)
Ask a question or share what worked for you. Comments are reviewed before they appear.
No comments yet. Be the first to start the discussion!