Repository navigation
feat(odin): Make Actions support opt-out per scheduled/continuous task #586
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
Changes from all commits
2c4c39a
8e9e9c7
46782ff
7ce1b0f
55a393c
b172f73
179cf8b
4ecfa94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,45 @@ def test_continuous_task_also_produces_start_stop_actions() -> None: | |
| assert by_name["Stop listener"].type == ActionType.stop_task | ||
|
|
||
|
|
||
| def test_tasks_are_actionable_by_default() -> None: | ||
| assert ScheduledTask.from_interval(interval="1h", name="a", target=lambda _: None).actionable | ||
| assert ScheduledTask.from_cron(cron="0 0 * * *", name="b", target=lambda _: None).actionable | ||
| assert ContinuousTask(name="c", target=lambda _: None).actionable | ||
| assert not StartupTask(name="d", target=lambda _: None).actionable | ||
|
|
||
|
|
||
| def test_opted_out_tasks_produce_no_actions_and_are_flagged_non_actionable() -> None: | ||
| extractor = _make_extractor() | ||
| extractor.add_task( | ||
| ScheduledTask.from_interval(interval="1h", name="sched", target=lambda _: None, actionable=False) | ||
| ) | ||
| extractor.add_task(ScheduledTask.from_cron(cron="0 0 * * *", name="cron", target=lambda _: None, actionable=False)) | ||
| extractor.add_task(ContinuousTask(name="cont", target=lambda _: None, actionable=False)) | ||
| extractor.add_task(ContinuousTask(name="kept", target=lambda _: None)) | ||
| req = _startup_request(extractor) | ||
| assert req.available_actions is not None | ||
| assert {a.name for a in req.available_actions if a.type != ActionType.custom} == {"Start kept", "Stop kept"} | ||
| assert req.tasks is not None | ||
| flags = {t.name: t.action for t in req.tasks} | ||
| assert {n: flags[n] for n in ("sched", "cron", "cont", "kept")} == { | ||
| "sched": False, | ||
| "cron": False, | ||
| "cont": False, | ||
| "kept": True, | ||
| } | ||
|
|
||
|
|
||
| def test_opted_out_task_name_does_not_reserve_action_names() -> None: | ||
|
vikramlc-cognite marked this conversation as resolved.
Resolved
|
||
| extractor = _make_extractor() | ||
| extractor.add_task(ContinuousTask(name="cont", target=lambda _: None, actionable=False)) | ||
| extractor.add_action(CustomAction(name="Start cont", target=lambda _: None)) | ||
| req = _startup_request(extractor) | ||
| assert req.available_actions is not None | ||
| by_name = {a.name: a for a in req.available_actions} | ||
| assert by_name["Start cont"].type == ActionType.custom | ||
| assert "Stop cont" not in by_name | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed a test gap: There is no test asserting that a dispatched action on a non-actionable task fails.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added test_dispatch_action_on_opted_out_task_reports_failed in |
||
| @pytest.mark.parametrize( | ||
| "action_name,expected_type,expected_task", | ||
| [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see dropping the guard meant widening
task: ScheduledTask | ContinuousTasktotask: Taskwhich now also admitsStartupTask. Just noting there is a tradeoff here. Are you fine with the widening?Separately, the docstring says "for an actionable task run", but opted-out scheduled tasks also run through here, so perhaps update the text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. These are remnants of the local testing I had done. Reverted the widening and also updated the docstring to cover opted-out tasks.