Python Automation: When a Scheduled Script Needs a Workflow Orchestrator

Test a daily import that can be retried safely. Use the failure it must recover from to choose between a script, Airflow, Prefect and Dagster.

A daily import reads its source, writes the report, then records success. If the process dies between the write and the success message, the next run may import the same rows twice. Moving the job to a scheduler gives it another chance to run. The write still needs a rule for retries.

Why workflow orchestration matters now

The example uses a SQLite database in a temporary directory. Each record has a date and a store. A retry writes the same logical record under the same key. A correction to the east store can replace that value without disturbing the west store. Execute the whole block with Python 3.

Python
import sqlite3
from pathlib import Path
from tempfile import TemporaryDirectory

def import_day(db, day, totals):
    with db:
        db.executemany(
            """INSERT INTO daily_total(day, store, cents) VALUES (?, ?, ?)
               ON CONFLICT(day, store) DO UPDATE SET cents = excluded.cents""",
            [(day, name, cents) for name, cents in totals],
        )

with TemporaryDirectory() as tmp:
    db = sqlite3.connect(Path(tmp) / "report.sqlite")
    try:
        db.execute("""CREATE TABLE daily_total(
            day TEXT, store TEXT, cents INTEGER, PRIMARY KEY(day, store))""")
        batch = [("east", 100), ("west", 250)]
        import_day(db, "2026-03-08", batch)
        import_day(db, "2026-03-08", batch)
        import_day(db, "2026-03-08", [("east", 125)])
        actual = db.execute("SELECT store, cents FROM daily_total ORDER BY store").fetchall()
        assert actual == [("east", 125), ("west", 250)]
    finally:
        db.close()

The key above identifies a daily aggregate. For a payment or other event stream, a different identifier and business rule may be necessary. This example covers retrying inserts and corrections. If a new file is a complete replacement snapshot, define how to remove stores absent from the replacement. SQLite UPSERT

Choosing the right orchestration tool

Operational questionWhere to startA test to run before choosing
One daily file, one operator, simple retries?A script and an operating-system scheduler. Write down when it last succeeded.Stop the process after the database commit and rerun the same date. Verify the totals.
Many scheduled intervals to backfill with explicit dependencies?Airflow DAGs. Decide what interval each run owns.Backfill two past dates without changing today’s data. Airflow DAG runs
Python control flow decides which tasks run?Prefect flows and tasks. Give retries to the step that can safely repeat.Fail one input partition once and observe the retried task and its state. Prefect tasks
People need to trace which datasets depend on another?Dagster assets and partitions. Define the output your team owns.Change one upstream date, inspect the downstream assets and rematerialize just that partition. Dagster assets

How each workflow handles a late file

With Airflow, use the run’s data interval to locate the input. Running yesterday’s interval today should still open yesterday’s file. A script that builds the filename from the current clock can silently overwrite the wrong partition during a backfill.

With Prefect, keep reading the source and writing the database in separate tasks when their retry behavior differs. If a read fails, retrying it can be inexpensive. Repeating a write after an unknown acknowledgment requires the stable key from the SQLite example.

With Dagster, model the dated report as a partitioned asset if operators need to see which daily output is missing. Before rematerializing a downstream report, check whether the original upstream file is still available and which revision it contains. A green status from an earlier run cannot identify a corrected input on its own.

Enterprise automation requirements

For the daily import, log the input revision, partition, row count and final status. Keep the business key separate from a run ID. Two attempts have different run IDs but may write the same day’s totals. Capture a missing-file failure and a partial failure in a runbook that a second operator can follow.

An automatic retry can repeat an external side effect, such as an email. Keep the report write separate from dispatch. Use the destination’s idempotency mechanism when available and record whether the notification was acknowledged. Validate any proposed action from an AI-assisted classification step against an allowed action list, and allow a reviewer to inspect uncertain classifications.

Making the right choice

Budget for operating the scheduler as well as writing the first job. Check who responds when credentials expire, which partitions need replaying and how to verify a corrected report. For the simpler case of running one job periodically, see our Python scheduling comparison.

Correction, November 25, 2026. The earlier article used market-size and download figures without a reproducible source and illustrated workflows with undefined services. The retry fixture and tool-specific recovery tests replace those claims.

Share this article

X Facebook LinkedIn Reddit Telegram

Your notes on this article

Your name or initials, note and date stay in this browser profile. Anyone using the profile can read them. Delete a note below or clear this site’s browser data. To reach the editors, report a correction.

No notes saved here