Install Command Details
Relevant source files
The following files were used as context for generating this wiki page:
The install command is a primary feature of the cron-ext utility, responsible for translating Meltano schedules into cron-compatible entries and persisting them to a target destination. Its main purpose is to automate the deployment of data integration pipelines by creating executable shell scripts and registering them in the system's crontab or outputting them for external management.
Sources: README.md:1-12, cron_ext/extension.py:107-133
Command Architecture and Execution Flow
The installation process involves retrieving schedule metadata from Meltano, generating wrapper scripts for each schedule, and updating the entry store. The command is triggered via the CLI and handled by the Cron extension class.
Sequence of Installation
The following sequence diagram illustrates the flow from the CLI invocation to the persistence of cron entries.
The logic ensures that existing project-specific entries are preserved while new or updated schedules are prepended to the managed section.
Sources: cron_ext/main.py:118-122, cron_ext/extension.py:107-133, cron_ext/stores/crontab.py:38-60
Script Generation Logic
For every schedule identified for installation, the extension generates a shell script located in the project's .meltano/run/cron-ext/ directory. These scripts serve as wrappers that encapsulate the environment required to run Meltano.
Script Composition
Each generated .sh file performs the following actions:
- Changes the directory to the
MELTANO_PROJECT_ROOT. - Exports relevant environment variables (including
PATHandVIRTUAL_ENV). - Executes the appropriate
meltano runormeltano eltcommand. - Pipes all output (stdout and stderr) to
/usr/bin/loggerwith the tagmeltano.
Sources: README.md:14-20, cron_ext/extension.py:85-105
Code Implementation
# From cron_ext/extension.py:97-104
command_script = self.cron_ext_dir / f"{schedule['name']}.sh"
command_script.write_text(
f"(cd '{self.meltano_project_dir}' && {env_str} "
f"meltano {cmd} {args}) 2>&1 | /usr/bin/logger -t meltano\n"
)
# Make the command script executable by the user who owns it
command_script.chmod(command_script.stat().st_mode | stat.S_IXUSR)
Sources: cron_ext/extension.py:97-105
Destination Stores
The install command supports two primary targets for the generated cron entries, defined by the Target enum.
| Target | Class | Behavior |
|---|---|---|
crontab | CrontabEntryStore | Appends or updates a block in the user's crontab delimited by # BEGIN/END MELTANO comments. |
stdout | StdoutEntryStore | Prints the cron entries directly to the standard output stream for custom piping. |
Sources: cron_ext/init.py:11-15, cron_ext/extension.py:44-48, cron_ext/stores/stdout.py:10-27, cron_ext/stores/crontab.py:17-36
Crontab Section Management
When targeting the system crontab, the extension manages a specific section identified by the MELTANO_PROJECT_ID. This prevents the utility from interfering with other cron jobs not managed by the specific Meltano project.
Sources: cron_ext/stores/crontab.py:38-60
Command Arguments and Options
The install command accepts optional arguments to filter which schedules are processed and options to define the target store.
| Argument/Option | Type | Description |
|---|---|---|
schedule_ids | List[str] | Optional list of specific schedule names to install. If omitted, all project schedules are installed. |
--target | Target | The destination for entries. Defaults to crontab. |
If a user provides schedule_ids that do not exist in the Meltano project, the extension logs an error listing the missing IDs and exits with a non-zero return code, though it will still attempt to install the valid IDs provided.
Sources: cron_ext/main.py:118-122, cron_ext/extension.py:126-133
Conclusion
The install command bridges the gap between Meltano's internal scheduling metadata and the system's cron daemon. By generating idempotent wrapper scripts and managing dedicated crontab sections, it provides a robust way to deploy Meltano jobs while maintaining environment isolation and logging through the standard system logger.