Miksus / rocketry

Modern scheduling library for Python
https://rocketry.readthedocs.io
MIT License
3.27k stars 108 forks source link

ENH: Convenient way to create new conditions #6

Closed Miksus closed 2 years ago

Miksus commented 2 years ago

Is your feature request related to a problem? Please describe. Creating simple conditions like a function that returns True-False and having that to the string parser engine could be easier.

Describe the solution you'd like

Proposed syntax:

from redengine.conditions import FuncCond

@FuncCond(syntax="is foo time"):
def is_foo():
    return True

# Then use
@FuncTask(start_cond="is foo time & daily")
def do_stuff():
    ...

The FuncCond could have following parameters:

Describe alternatives you've considered

Alternatively using the standard method:

import re
from pathlib import Path
from redengime.core import BaseCondition

class IsFoo(BaseCondition):

    __parsers__ = {
        "is foo time": "__init__"
    }

    def __init__(self):
        pass

    def __bool__(self):
        return True

# Then use
@FuncTask(start_cond="is foo time & daily")
def do_stuff():
    ...
Miksus commented 2 years ago

Merged with pull request.