Cron Entry Generator
Relevant source files
The following files were used as context for generating this wiki page:
The Cron Entry Generator is a core functional component of the cron-ext utility. Its primary purpose is to transform Meltano schedule definitions into valid crontab entries and executable shell scripts. This allows Meltano jobs (both legacy elt and modern run commands) to be managed by the standard system cron daemon.
The generator operates by inspecting the Meltano project's schedules, creating environment-aware wrapper scripts in a dedicated directory, and then formatting a crontab string that points to these scripts. It supports different output targets, including the local system's crontab or stdout for manual integration.
Sources: README.md:3-13, cron_ext/extension.py:16-43
Architecture and Data Flow
The generation process follows a structured pipeline: retrieving schedules from Meltano, generating shell script wrappers, and formatting the final cron entries.
Logic Flow
The following diagram illustrates the lifecycle of a cron entry from Meltano schedule to crontab entry:
The generator uses meltano schedule list --format=json to acquire the source data for processing.
Sources: cron_ext/extension.py:73-81, cron_ext/extension.py:108-115
Entry Generation Components
Shell Script Wrapper Generation
For every schedule, the generator creates a .sh file in the project's .meltano/run/cron-ext/ directory. These scripts are essential because they capture the environment state (like PATH and VIRTUAL_ENV) and ensure the execution happens within the correct project directory.
| Component | Logic / Description |
|---|---|
| Directory | .meltano/run/cron-ext/ |
| Environment | Inherits PATH and VIRTUAL_ENV from the installer's environment. |
| Execution | Uses (cd 'PROJECT_ROOT' && ENV_VARS meltano COMMAND ARGS). |
| Logging | Pipes all output to /usr/bin/logger -t meltano. |
| Permissions | Automatically applies stat.S_IXUSR to make scripts executable. |
Sources: cron_ext/extension.py:89-106, README.md:15-22
Cron String Formatting
The generator produces a standardized cron line for each schedule. It uses a specific regex pattern to parse and identify these entries later during listing or uninstallation.
# The pattern used to identify generated entries
entry_pattern = re.compile(r"(?i)^.+?'(?P<path>/?(?:.*/)(?P<name>.*)\.sh)'.*$")
Sources: cron_ext/entry.py:6-7
A typical generated entry looks like:
0 0 * * * '/path/to/project/.meltano/run/cron-ext/daily.sh'
Sources: README.md:11-13
Store Integration
The generated entries are passed to an EntryStore, which determines how the strings are persisted.
The CrontabEntryStore identifies a specific block in the system crontab using a project-specific ID to ensure it only manages entries belonging to the current Meltano project.
Sources: cron_ext/stores/base.py:11-28, cron_ext/stores/crontab.py:20-40, cron_ext/stores/stdout.py:12-25
Configuration and Parameters
The generation behavior is controlled via CLI arguments passed to the install and list commands.
| Parameter | Type | Description |
|---|---|---|
schedule_ids | List[str] | Optional list of specific schedules to generate entries for. |
target | Enum | Either crontab (write to system) or stdout (print to terminal). |
orphaned | Bool | Used during listing to filter entries found in crontab but missing in meltano.yml. |
Sources: cron_ext/main.py:61-115
Conclusion
The Cron Entry Generator provides a bridge between Meltano's internal scheduling logic and the system-level cron utility. By encapsulating environment variables and project paths into executable wrapper scripts, it ensures that scheduled jobs run reliably regardless of the user's interactive shell state. Through the use of project-specific markers in the crontab, it maintains a clean separation between Meltano-managed tasks and other system cron jobs.