Extension Core Logic
Relevant source files
The following files were used as context for generating this wiki page:
The Extension Core Logic of cron-ext facilitates the integration between Meltano schedules and the system crontab. It translates Meltano's internal schedule definitions into executable shell scripts and manages the lifecycle of these schedules within a system-level cron environment or an alternative output stream.
Sources: README.md, cron_ext/extension.py:1-25
Architecture and Component Overview
The extension is built on a modular architecture that separates the Meltano environment interaction from the persistence layer (the "Store"). The Cron class acts as the primary orchestrator, utilizing the Meltano EDK (Extension Development Kit) to interface with the project environment.
Core Class Hierarchy
The following diagram illustrates the relationship between the main extension class and the storage backends.
Schedule Processing and Installation
The installation logic involves two primary steps: generating wrapper shell scripts for Meltano commands and updating the target cron store.
Script Generation Logic
For every schedule, cron-ext generates a .sh file located in .meltano/run/cron-ext/. These scripts encapsulate the environment variables (including PATH and VIRTUAL_ENV), change to the project directory, and execute the appropriate meltano run or meltano elt command.
| Element | Description |
|---|---|
| Path | .meltano/run/cron-ext/{schedule_name}.sh |
| Environment | Includes current PATH and VIRTUAL_ENV if active |
| Command | (cd '{root}' && {env} meltano {cmd} {args}) 2>&1 | /usr/bin/logger -t meltano |
| Permissions | Set to executable (stat.S_IXUSR) |
Sources: cron_ext/extension.py:75-103, README.md
Installation Flow
When a user runs the install command, the extension retrieves the current project schedules and filters them based on user input.
Storage Backends
The extension supports different targets for the generated cron entries via the EntryStore abstraction.
Crontab Storage (CrontabEntryStore)
This store manages a specific section in the system crontab identified by the MELTANO_PROJECT_ID. It uses delimiters to ensure that manual edits to the crontab are preserved.
- Delimiters:
# ----- BEGIN MELTANO CRONTAB SECTION ({id}) -----and# ----- END MELTANO CRONTAB SECTION ({id}) -----. - Management: The store is "managed," meaning it can read existing entries, update them, and delete them.
- Regex Parsing: Uses
entry_patternto identify paths and names within cron lines.
Sources: cron_ext/stores/crontab.py:16-103, cron_ext/entry.py:5-8
Stdout Storage (StdoutEntryStore)
A non-managed store used for previewing entries or piping them to other tools.
- Reading: Always returns an empty tuple.
- Writing: Prints the cron lines directly to the standard output.
Sources: cron_ext/stores/stdout.py:11-30
Uninstallation and Cleanup
Uninstallation logic filters existing entries in the store against the project's current schedules.
Command Reference
The extension exposes several commands through the Typer-based CLI.
| Command | Functionality | Key Parameters |
|---|---|---|
install | Generates scripts and updates the store. | schedule_ids, --target |
list | Lists installed entries for the project. | --name-only, --orphaned, --target |
uninstall | Removes entries and associated scripts. | schedule_ids, --all, --target |
describe | Returns EDK metadata about the extension. | --format |
Sources: cron_ext/main.py:31-155
Conclusion
The cron-ext Core Logic effectively bridges Meltano projects with system-level task scheduling. By wrapping Meltano commands in environment-aware shell scripts and managing a dedicated section within the system crontab, it provides a seamless way to operationalize Meltano schedules without manually configuring cron jobs.
Sources: README.md, cron_ext/extension.py:179-191