Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Minimal task #47

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions rocketry/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ class Config:

parameters: Parameters = Parameters()

start_cond: BaseCondition = AlwaysFalse() #! TODO: Create get_start_cond so that this could also be as string (lazily parsed)
end_cond: BaseCondition = AlwaysFalse()
start_cond: Optional[BaseCondition] = AlwaysFalse() #! TODO: Create get_start_cond so that this could also be as string (lazily parsed)
end_cond: Optional[BaseCondition] = AlwaysFalse()

on_startup: bool = False
on_shutdown: bool = False
Expand All @@ -193,6 +193,8 @@ def parse_start_cond(cls, value, values):
session = values['session']
if isinstance(value, str):
value = parse_condition(value, session=session)
elif value is None:
value = AlwaysFalse()
return copy(value)

@validator('end_cond', pre=True)
Expand All @@ -201,6 +203,8 @@ def parse_end_cond(cls, value, values):
session = values['session']
if isinstance(value, str):
value = parse_condition(value, session=session)
elif value is None:
value = AlwaysFalse()
return copy(value)

@validator('logger_name', pre=True, always=True)
Expand Down
9 changes: 8 additions & 1 deletion rocketry/test/app/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rocketry import Session
from rocketry.tasks import CommandTask
from rocketry.tasks import FuncTask
from rocketry.conds import false

def set_logging_defaults():
task_logger = logging.getLogger("rocketry.task")
Expand Down Expand Up @@ -46,6 +47,10 @@ def test_app_tasks():
app = Rocketry(config={'task_execution': 'main'})

# Creating some tasks
@app.task()
def do_never():
...

@app.task('daily')
def do_func():
...
Expand All @@ -55,12 +60,14 @@ def do_func():
app.task('daily', name="do_script", path=__file__)

# Assert and test tasks
assert len(app.session.tasks) == 3
assert len(app.session.tasks) == 4

assert isinstance(app.session['do_func'], FuncTask)
assert isinstance(app.session['do_command'], CommandTask)
assert isinstance(app.session['do_script'], FuncTask)

assert app.session['do_never'].start_cond == false

def test_app_run():
set_logging_defaults()

Expand Down