Python, from Zero, for AILesson 88 of 89

Module 9 · Building the thing: a small AI program, end to end

Running it every morning: cron, a lock file, and a job that is safe to run twice

In this lesson

  • 9 min read
  • 9 reading sections
  • Knowledge check
  • Lesson 9 of 10 in this chapter

This chapter’s goalAssemble a complete tool from the course’s parts (a chat loop with bounded history, injection-resistant prompt templates, a sqlite response cache, a document chunker, a local embedding search over your own notes, a free local model as the fallback provider) expose it through a Gradio interface and a FastAPI endpoint, run it on a schedule without double-processing, and gate every change behind a GitHub Actions job that runs the tests.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:39Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 11Free · no account needed
Lesson steps

The scheduler does very little

A scheduler starts your program at a time. That is all. Everything else (where it runs, what it can see, what happens if it is still running when the next start arrives, what happens if it runs twice) is your program’s problem, and a script that works perfectly by hand fails under a scheduler for exactly those reasons.

cron, and the free alternatives

On macOS and Linux, crontab -e opens a file of lines:

Text
# minute hour day month weekday   command
0 7 * * *   cd /home/asha/tagger && /home/asha/tagger/.venv/bin/python -m tagger.daily >> logs/daily.log 2>&1

Five time fields, then the command. 0 7 * * * is seven every morning. */15 * * * * is every fifteen minutes. The site crontab.guru decodes any line.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘Running it every morning: cron, a lock file, and a job that is safe to run twice’, in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/scheduling-and-idempotent-jobs (Accessed: 21 November 2026).