Rocketry Documentation

repository·master·Indexed 25 days ago

https://github.com/miksus/rocketry

A modern, statement-based scheduling framework for Python. Rocketry allows developers to build complex automation and task-driven applications using extensible scheduling logic, including support for intervals, cron expressions, and custom conditions. It features flexible execution modes (main, async, thread, process), task dependency pipelines using after_success, and a natural language syntax for defining time-based execution and task status conditions.

Tokens
25.7K
Snippets
88
Records
171
Agent score
85%

What's inside Rocketry

  1. Overview of Rocketry scheduling features

    master

    Rocketry is a modern, statement-based scheduling framework for Python. It is designed to be simple to set up while remaining robust and extensible for large-scale applications or autonomous engines.

    Key capabilities include:

    • Powerful Scheduling: Supports various strategies including cron and custom scheduling statements.
    • Concurrency Support: Handles tasks using async, threading, or multiprocessing.
    • Task Management: Supports parametrization and task pipelining.
    • Extensibility: Features a modifiable runtime session and allows for custom scheduling logic.
  2. Understand Parameterization Hierarchy

    master

    Rocketry uses key-value pairs called parameters to pass values to tasks. Parameters can be static instances or dynamic arguments. There is a specific hierarchy of precedence; if the same key exists at multiple levels, the higher level overrides the lower one:

    1. Batch parameters (Highest precedence)
    2. *Task parameters
    3. Function parameters
    4. Session parameters (Lowest precedence)
  3. Understand Rocketry's core components

    master

    Rocketry is organized into several key components that manage tasks, scheduling, and execution logic:

    • rocketry.Rocketry: The high-level application interface used to create tasks, conditions, and parameters using a simple syntax. It manages a rocketry.Session and is typically used to start the scheduling session.
    • rocketry.Session: A scheduling session containing all tasks, parameters, conditions, and configurations. It is the primary interface for runtime communication, such as creating/updating/deleting tasks, running tasks manually, disabling tasks, or shutting down/restarting the scheduler.
    • rocketry.core.Task: The base class for all units of work (functions, commands, or code). Tasks support scheduling, manual execution, conditional execution, timeouts, threading/processing, async execution, parameterization, and pipelining.
    • rocketry.core.BaseCondition: The base class for conditions. A condition is a boolean statement (true/false) based on time, state, or other factors, used to control when tasks run, terminate, or when the scheduler shuts down.
    • rocketry.core.TimePeriod: The base class for abstract intervals (e.g., a week or a specific time of day). These are used to define scheduling windows.
    • rocketry.core.Parameters: A dictionary-like class used to pass key-value pairs as input arguments to tasks.
    • rocketry.core.BaseArgument: The base class for abstracted arguments. These represent values (like return values from other tasks or functions) that are resolved into actual values just before task execution.
  4. Understand the Rocketry core components

    master

    Rocketry's ecosystem is composed of four primary layers that manage the lifecycle of task scheduling and execution:

    • Rocketry: The top-level interface used to interact with the system.
    • Session: The medium-level interface that manages configuration.
    • Scheduler: Manages the overall flow and timing of the system.
    • Task: Defines and handles the actual execution logic of a unit of work.
  5. Understand Rocketry Task Logging

    master

    Rocketry's logging system extends the standard Python logging library using Red Bird. It uses a specific logger named rocketry.task to record task actions. To ensure visibility into task lifecycle, this logger should not filter out the INFO level.

    Task actions logged include:

    • run: Task starts.
    • success: Task finishes without exceptions.
    • fail: Task finishes with an error.
    • terminate: Task is terminated before completion.
    • inaction: Task did nothing (requires raising a special exception).
    • crash: Task previously crashed silently and is no longer running.
  6. Understand Rocketry subcomponents: Conditions, TimePeriods, and Parameters

    master

    Rocketry uses several specialized subcomponents to refine task behavior:

    • Condition: A logic statement that evaluates to true or false based on time or system state, used to determine if a task should run.
    • TimePeriod: An abstraction used to define specific time intervals or periods (e.g., 'today', a specific time of day, or a specific week).
    • Parameters: Key-value pairs passed into tasks.
    • Arguments: The specific values associated with the keys in a Parameters object.
  7. Understand Rocketry conditions

    master

    Rocketry's scheduling system uses conditions that evaluate to either True or False. A task is triggered, terminated, or the scheduler is shut down based on these boolean evaluations.

    Conditions can be used in three contexts:

    1. Start condition: The task runs if the condition is True.
    2. End condition: A running task terminates if the condition is True.
    3. Shut condition: The scheduler shuts down if the condition is True (useful for testing).

    You can combine conditions using logical operations: AND, OR, and NOT, and nest them using parentheses.

  8. Understand Condition Classes in Rocketry

    master
    Condition classes serve as the low-level mechanics of the Rocketry condition system. Every condition used within the framework is an instance of these underlying condition classes. Additionally, the system provides time period utilities to support time-related conditions, enabling checks such as whether a specific time falls within a given day of the month, a day of the week, or a specific time range.
  9. Compare Rocketry with scheduling alternatives

    master

    Rocketry is a Python-based automation framework designed for complex scheduling and task pipelining. Use the following comparison to decide if Rocketry fits your needs:

    Key Unique Features of Rocketry

    • Statement-based scheduling: A unique, extensible condition system for complex scheduling needs.
    • Time periods: Sophisticated and robust time period management.
    • Parametrization: Enables passing the output of one task as the input for another (task pipelining).
    • No assumptions: Does not dictate project structure; integrates easily with other frameworks and allows flexible log redirection.

    Comparison Summary

    AlternativeChoose Rocketry if...Choose Alternative if...
    CrontabBuilding a system, need task pipelining, complex scheduling, or working on Windows.Need a lightweight solution, not using Python, or running independent scripts.
    APSchedulerBuilding an automation system, need complex/custom scheduling, or task pipelining.You need tasks stored in a database rather than Python code.
    CeleryBuilding an automation system, need complex/custom scheduling, or working on Windows.Running background tasks for web servers, need high performance, or distributed execution.
    AirflowNeed complex scheduling, working on Windows, easy setup, or building an application.Building standard data pipelines, need out-of-the-box data engineering tools, or distributed execution.