🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Data Management / Database Administration › ETL Pipelines: Extract, Transform, and Load for Database Administration › Lesson 6
TEC-DATA86-06 · Lesson 6 · 9 clock hours · demo

Pipeline Orchestration with a Scheduler

Objective. Students will schedule an end-to-end ETL pipeline using cron (Linux) or Task Scheduler (Windows) and confirm that the pipeline runs unattended at a specified interval and sends an email-style notification on success or failure.

⚠ Pending professional review

This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.

VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.

Pipeline Orchestration with a Scheduler

Once an ETL pipeline works correctly when run by hand, the next step is to run it automatically—on a schedule, without anyone sitting at a keyboard. This is called pipeline orchestration. In production database environments, ETL jobs commonly run overnight, hourly, or on some other fixed interval so that target tables stay fresh and analysts find current data when they arrive in the morning.

This lesson covers two scheduling tools every DBA should know: cron on Linux and Task Scheduler on Windows. It also introduces the pattern of writing a notification record to the database after each run, and provides a first look at Apache Airflow, the leading open-source orchestration platform.

How cron Works

cron is a time-based job scheduler built into Linux and macOS. Each user has a personal list of scheduled commands called a crontab (cron table). You edit it with `crontab -e` and list it with `crontab -l`.

Each line in a crontab has five time fields followed by the command:

```

│ │ │ │ │

│ │ │ │ └─ day of week (0=Sunday … 6=Saturday)

│ │ │ └─── month (1-12)

│ │ └───── day of month (1-31)

│ └─────── hour (0-23)

└───────── minute (0-59)

```

To run a Python ETL script every night at 2:00 AM:

```

0 2 * /usr/bin/python3 /home/student/etl/run_pipeline.py >> /home/student/etl/etl.log 2>&1

```

The `>> ... 2>&1` portion appends both standard output and error messages to a log file. Always redirect output to a log file; without it, cron silently discards messages and troubleshooting becomes very difficult.

Important operating practice: Use full absolute paths for both the interpreter and the script. cron runs with a minimal environment and may not find commands that work fine in your interactive shell.

Windows Task Scheduler

On Windows, the equivalent tool is Task Scheduler. You create a task, set a trigger (daily, weekly, on a schedule), and point the action at the Python interpreter with the script path as an argument. Like cron, Task Scheduler can redirect output to a log file using a wrapper batch script. The underlying principle—run a command at a defined time without human intervention—is identical on both platforms.

Writing a Notifications Table

Scheduled jobs run unattended, so you need a reliable way to know whether a run succeeded or failed. A simple and portable pattern is to write a summary row to a notifications table in PostgreSQL at the end of every pipeline run. A minimal table might look like:

```sql

CREATE TABLE etl_notifications (

id SERIAL PRIMARY KEY,

pipeline TEXT NOT NULL,

status TEXT NOT NULL, -- 'SUCCESS' or 'FAILURE'

rows_loaded INTEGER,

run_at TIMESTAMPTZ DEFAULT now(),

message TEXT

);

```

At the end of your Python ETL script, insert a row:

```python

cur.execute(

"INSERT INTO etl_notifications (pipeline, status, rows_loaded, message) "

"VALUES (%s, %s, %s, %s)",

('nightly_sales', 'SUCCESS', row_count, 'Pipeline completed normally')

)

conn.commit()

```

If an exception is caught, insert a FAILURE row instead and include the error text in the message column. This gives you a durable, queryable audit trail—an approach used by commercial orchestrators such as Informatica and Azure Data Factory, scaled up with richer metadata.

Introduction to Apache Airflow

For complex pipelines with many interdependent steps, a dedicated orchestration platform adds significant value. Apache Airflow is a widely used open-source tool. In Airflow, you define a pipeline as a DAG (Directed Acyclic Graph)—a Python file that describes tasks and the order they must run. Key concepts:

The DAG structure makes dependencies explicit and visual, which reduces errors compared to maintaining complex cron entries manually. Everything you built with cron and the notifications table maps directly to Airflow concepts: the schedule is the DAG's `schedule_interval`, the log file becomes Airflow task logs, and the notifications table pattern is replaced by Airflow's built-in metadata database.

Safety and Professional Practices

Scheduled jobs run with whatever permissions the user account has. Follow the principle of least privilege: the database user your ETL script connects as should have only the permissions it needs—no superuser rights for a routine load job. Store database credentials in environment variables or a secrets manager, never hard-coded in the script.

Before activating a schedule in production, test the full run manually and confirm the log file and notifications table record look correct. Keep a retention policy for log files; unbounded log growth can fill a disk and halt the server. When changing a live crontab on a shared Linux system, verify with `crontab -l` immediately after editing so you can catch syntax errors before the next scheduled window.

Key terms8

cronA Linux/Unix time-based job scheduler that runs commands automatically at specified intervals defined in a crontab file.
crontabThe configuration file listing scheduled commands for a cron user; managed with the crontab -e (edit) and crontab -l (list) commands.
pipeline orchestrationThe automated scheduling, sequencing, and monitoring of ETL tasks so they run reliably without manual intervention.
DAG (Directed Acyclic Graph)In Apache Airflow, a Python-defined pipeline where nodes are tasks and directed edges define the order of execution, with no circular dependencies.
operatorIn Airflow, a template that defines what kind of work a task performs, such as PythonOperator, BashOperator, or PostgresOperator.
notifications tableA database table that stores a status record (success or failure, row count, timestamp) written by an ETL script after each run, providing an auditable log.
least privilegeA security principle that grants each user or process only the minimum permissions required to perform its function, reducing risk if credentials are compromised.
schedule intervalThe setting in a cron entry or Airflow DAG definition that controls how frequently the pipeline runs, expressed as a cron expression or a predefined shorthand.
In class: Instructor demonstrates configuring a cron job on a Linux VM to run an ETL Python script nightly; students replicate the configuration and verify the cron entry with crontab -l. · Extend the ETL script to send a completion notification by writing a summary record (status, row count, run timestamp) to a notifications table in PostgreSQL, simulating the pattern used by commercial orchestrators. · Review the orchestration screen of an open-source tool (Apache Airflow or similar) via a live instructor demo: identify DAG structure, task dependencies, retry settings, and logging output; map these features to the manual patterns built in earlier lessons.
Materials: Linux VM with cron, PostgreSQL 15, Python 3, instructor-prepared Airflow demo environment (read-only access), Airflow documentation (airflow.apache.org), cron syntax reference
Check: Student shows a cron job entry, a test run log file, and a populated notifications table row; instructor verifies the scheduled run executed correctly; pass = all three artifacts present and correct

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

ETL pipeline operations and scheduling
1. A student types `0 3 * * *` as the time fields in a crontab entry. When will that job run?
ETL pipeline operations and scheduling
2. Which command lets a student verify that a new cron entry was saved correctly without opening an editor?
ETL pipeline operations and scheduling
3. An ETL script runs from cron but produces no output and no log. What is most likely the cause?
Database security and data governance
4. Why should database credentials never be hard-coded inside a Python ETL script?
ETL pipeline design and orchestration tools
5. In Apache Airflow, what is a DAG?
Data governance and pipeline monitoring
6. A notifications table row is inserted at the end of each ETL run. Which combination of columns provides the most useful audit information?
ETL pipeline operations and scheduling
7. A student needs to run an ETL script every weekday at 6:30 AM. Which crontab time expression is correct?
ETL pipeline design and orchestration tools
8. Which Airflow feature most directly replaces the manual practice of inserting a FAILURE row into a notifications table when an ETL task fails?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.