Package Structure & Initialization
Relevant source files
The following files were used as context for generating this wiki page:
The cron-ext package is a Meltano utility extension designed to provide basic job scheduling via the system's cron utility. It bridges the gap between Meltano's internal schedule definitions and the host environment's execution capabilities by generating shell scripts and managing cron entries. The extension follows the Meltano Extension Development Kit (EDK) architecture, implementing a custom extension class and a CLI entry point for integration with the Meltano ecosystem.
Sources: README.md:1-8, cron_ext/extension.py:27-30, pyproject.toml:1-10
CLI Entry Point and Configuration
The application entry point is defined in cron_ext/main.py, utilizing the typer library to create a command-line interface. The CLI is registered as a script named cron in the project's metadata.
Sources: pyproject.toml:58, cron_ext/main.py:21-25
CLI Initialization Flow
When the CLI is invoked, it initializes logging configurations and sets up the primary typer.Typer application. Global options such as log_level and meltano_log_json are handled via a callback that runs before specific subcommands.
The diagram shows the command flow from invocation to execution of specific logic.
Sources: cron_ext/main.py:145-177
Core Extension Architecture
The heart of the package is the Cron class, which inherits from meltano.edk.extension.ExtensionBase. This class handles the logic for directory management, schedule retrieval, and store selection.
Sources: cron_ext/extension.py:32-35
The Cron Class Structure
| Component | Description | Source |
|---|---|---|
store | An instance of EntryStore determined by the Target enum. | extension.py:48-51 |
meltano_project_dir | The resolved path to the root Meltano project. | extension.py:53 |
cron_ext_dir | Path to .meltano/run/cron-ext/ where generated .sh scripts live. | extension.py:73-77 |
meltano_schedule | Cached property containing JSON schedule data from Meltano. | extension.py:80-88 |
Initialization Logic
During instantiation, the extension determines its operational mode based on a Target (either crontab or stdout). This selection dictates which EntryStore implementation will be used for persisting or displaying cron entries.
This class diagram illustrates the relationship between the EDK base, the Cron extension, and the pluggable storage backend.
Sources: cron_ext/extension.py:48-53, cron_ext/stores/base.py:11-15, cron_ext/stores/init.py:1-5
Storage and Persistence Layer
The package utilizes a strategy pattern for managing cron entries, located in the cron_ext.stores subpackage.
Entry Store Types
- CrontabEntryStore: Interfaces directly with the system
crontabcommand. It identifies sections belonging to specific Meltano projects using comment headers containing theMELTANO_PROJECT_ID. - StdoutEntryStore: A non-managed store that simply prints generated cron entries to standard output. It is used when the user wants to handle the output manually.
Sources: cron_ext/stores/crontab.py:17-19, cron_ext/stores/stdout.py:11-13, cron_ext/init.py:11-14
Data Flow for Crontab Updates
When installing schedules, the extension reads the existing crontab, locates the project-specific section, merges new entries, and writes the content back.
The sequence diagram details the process of reading, modifying, and saving the crontab for a specific project.
Sources: cron_ext/stores/crontab.py:38-66, cron_ext/subprocess.py:23-45
Execution Environment Setup
The initialization process ensures that the host environment is ready for cron job execution. This involves:
- Directory Creation: Ensuring
.meltano/run/cron-ext/exists to store the executable shell wrappers. - Path & VirtualEnv Resolution: Capturing the
PATHandVIRTUAL_ENVvariables at the time of installation to ensure the cron job runs in the same environment as the CLI. - Script Permissions: Automatically applying executable bits (
stat.S_IXUSR) to generated shell scripts.
Sources: cron_ext/extension.py:73-77, cron_ext/extension.py:91-110
Summary of Initialization Components
| File | Purpose |
|---|---|
cron_ext/__init__.py | Defines the APP_NAME and Target enumeration. |
cron_ext/main.py | Configures the Typer CLI and logging. |
cron_ext/extension.py | Implements the core Cron extension class logic. |
cron_ext/stores/base.py | Defines the abstract interface for cron entry persistence. |
cron_ext/subprocess.py | Provides a wrapper for executing system commands like crontab or meltano. |
Sources: cron_ext/init.py:1-14, cron_ext/main.py:21-30, cron_ext/extension.py:32-60, cron_ext/stores/base.py:11-31, cron_ext/subprocess.py:18-21