Uninstall Command Details
Relevant source files
The following files were used as context for generating this wiki page:
The uninstall command in cron-ext is responsible for removing Meltano-managed job schedules from the system's cron configuration. Its primary purpose is to safely strip out entries that were previously added by the extension, ensuring that non-Meltano crontab entries remain untouched. The command can target specific schedules, all schedules associated with the current Meltano project, or all schedules regardless of their current status in meltano.yml.
This command operates through the Cron extension class, which interacts with an EntryStore. The behavior varies significantly depending on whether the store is "managed" (like the crontab target) or "unmanaged" (like stdout). Uninstallation is only supported for managed stores, as there is no persistent state to remove in an unmanaged output stream.
Sources: cron_ext/main.py:106-121, cron_ext/extension.py:126-169, README.md:65-80
Architecture and Command Flow
The uninstallation process follows a structured flow from the CLI entrypoint down to the file system and crontab modifications. The Cron class determines which entries to delete based on the provided arguments and the current state of the Meltano project.
Sequence of Operations
The following diagram illustrates how the uninstall command processes a request:
Uninstallation Predicates and Selection Logic
The command uses a predicate logic to determine which cron entries should be removed. The selection behavior is governed by the presence of specific schedule_ids or the --all flag.
| Mode | Predicate Logic | Description |
|---|---|---|
| Specific IDs | lambda x: x in schedule_ids | Removes only the schedules explicitly named in the command arguments. |
| All Flag | lambda _: True | Removes all entries found within the Meltano section of the crontab for that project ID. |
| Default | lambda x: x in meltano_schedule_ids | Removes only entries that currently exist as active schedules in the Meltano project. |
Sources: cron_ext/extension.py:143-152, cron_ext/main.py:106-121
Entry Identification
To correctly identify which lines in the crontab belong to which schedule, the extension uses a regular expression to parse the entry line. It specifically looks for the path to the shell script created during installation.
# From cron_ext/entry.py
entry_pattern = re.compile(r"(?i)^.+?'(?P<path>/?(?:.*/)(?P<name>.*)\.sh)'.*$")
Sources: cron_ext/entry.py:6
Store Management and Limitations
The uninstallation functionality is strictly tied to the EntryStore implementation. The EntryStore abstract base class defines the interface, but the capability to uninstall is determined by the is_managed property.
- CrontabEntryStore: Set to
is_managed = True. It identifies the project-specific section using headers like# ----- BEGIN MELTANO CRONTAB SECTION (project_id) -----. Uninstallation modifies this section and deletes the associated.shscripts in.meltano/run/cron-ext/. - StdoutEntryStore: Set to
is_managed = False. Attempting to rununinstallagainst this target will raise aValueError.
Sources: cron_ext/stores/crontab.py:19, cron_ext/stores/stdout.py:15, cron_ext/extension.py:140-141
Cleanup of Assets
When an entry is uninstalled, the extension performs two main actions:
- Crontab Cleanup: It updates the crontab file by removing the lines that match the predicate.
- Script Deletion: It attempts to delete the execution script (e.g.,
daily.sh) from the project's internal directory.
# Cleanup logic in cron_ext/extension.py
for entry in prev_entries:
match = entry_pattern.fullmatch(entry)
if match and predicate(match["name"]):
with suppress(FileNotFoundError):
Path(match["path"]).unlink()
Sources: cron_ext/extension.py:165-169
Command Arguments Summary
| Argument | Type | Description |
|---|---|---|
schedule_ids | List[str] (Optional) | The names of specific schedules to remove. |
--all / -a | Flag | If set, uninstalls all schedules for the project, including orphaned ones. |
--target | Enum (crontab, stdout) | The storage backend. Defaults to crontab. |
Sources: cron_ext/main.py:106-116
The uninstall command ensures project isolation by only operating on crontab entries identified by the MELTANO_PROJECT_ID environment variable within the store's section finding logic.
Sources: cron_ext/stores/crontab.py:24, cron_ext/stores/crontab.py:86-92