pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.93k stars 383 forks source link

Crontab fact can't handle same command in multiple entries #1192

Closed JakkuSakura closed 1 week ago

JakkuSakura commented 3 months ago

I noticed that Crontab uses the following data structure. If a command appears twice, the old entry will get overwritten. It may has something to do with #1189, but I'm not sure

class Crontab(FactBase[Dict[str, CrontabDict]]):
    """
    Returns a dictionary of cron command -> execution time.

    .. code:: python

        {
            "/path/to/command": {
                "minute": "*",
                "hour": "*",
                "month": "*",
                "day_of_month": "*",
                "day_of_week": "*",
            },
            "echo another command": {
                "special_time": "@daily",
            },
        }
    """

Proposal: use the new data structure

  {
    "entries": [
        {
          "env": "CRON_TZ",
          "value": "UTC"
        },
        {
          "command": "/path/to/command",
          "minute": "*"
        },
        {
          "command": "echo another command",
          "special_time": "@daily",
        },
    ],
    "/path/to/command": {
        "minute": "*",
        "hour": "*",
        "month": "*",
        "day_of_month": "*",
        "day_of_week": "*",
    },
    "echo another command": {
        "special_time": "@daily",
    },
}

and deprecate old structure