merlinz01 / redpepper

A state-based server management system written in Python
MIT License
1 stars 0 forks source link

Revisit state syntax #69

Open merlinz01 opened 2 weeks ago

merlinz01 commented 2 weeks ago

The current state syntax works well, but has these drawbacks:

Better:

name: Foo the bar
type: command.Run
args:
    command: cat foo | bar --stdin
    user: baz
if:
    ...
onchange:
    ...
merlinz01 commented 5 days ago

Nope, the real way to do it is with good ol' Python itself. Way more flexible, support for it everywhere, type checking, docstrings, etc.

Something like this:

state = State(
    "test",
    [
        State(
            "Foo the bar",
             command.Run("cat foo | bar --stdin"),
            onchange=service.Restart('blah'),
        ),
        State(
            "Foo the baz",
             command.Run("cat foo | baz "),
             cond=Or(Cmd("test -f /nonexistent"), sys.platform == "linux"),
        ),
        ...
    ]
)

if __name__ == '__main__':
  state.run()

This will also make it easy to implement goodies like having "defer" states that only run once if triggered at least once.