-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
206 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
includes: | ||
- has_factory.yaml | ||
- has_name.yaml | ||
|
||
properties: | ||
period_s: | ||
type: number | ||
default: 1.0 | ||
exclusiveMinimum: 0.0 | ||
|
||
average_depth: | ||
type: integer | ||
default: 10 | ||
minimum: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
type: object | ||
required: [factory] | ||
additionalProperties: false | ||
|
||
properties: | ||
factory: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
required: [name] | ||
|
||
properties: | ||
name: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,74 @@ | ||
""" | ||
A module implementing task-factory registration. | ||
""" | ||
|
||
# built-in | ||
from typing import Dict as _Dict | ||
from typing import List as _List | ||
|
||
# third-party | ||
from vcorelib.names import obj_class_to_snake | ||
|
||
# internal | ||
from runtimepy.net.arbiter.base import ( | ||
BaseConnectionArbiter as _BaseConnectionArbiter, | ||
) | ||
from runtimepy.net.arbiter.task import ArbiterTask as _ArbiterTask | ||
from runtimepy.net.arbiter.task import TaskFactory as _TaskFactory | ||
|
||
Factory = _TaskFactory[_ArbiterTask] | ||
|
||
|
||
class TaskConnectionArbiter(_BaseConnectionArbiter): | ||
"""A class for managing task factories.""" | ||
|
||
def _init(self) -> None: | ||
"""Additional initialization tasks.""" | ||
|
||
super()._init() | ||
self._task_factories: _Dict[str, Factory] = {} | ||
self._task_names: _Dict[Factory, _List[str]] = {} | ||
|
||
def factory_task( | ||
self, factory: str, name: str, period_s: float = None, **kwargs | ||
) -> bool: | ||
""" | ||
Register a periodic task from one of the registered task factories. | ||
""" | ||
|
||
result = False | ||
|
||
if factory in self._task_factories: | ||
result = self.task_manager.register( | ||
self._task_factories[factory].kind(name, **kwargs), | ||
period_s=period_s, | ||
) | ||
|
||
return result | ||
|
||
def register_task_factory( | ||
self, factory: Factory, *namespaces: str | ||
) -> bool: | ||
"""Attempt to register a periodic task factory.""" | ||
|
||
result = False | ||
|
||
assert isinstance(factory, _TaskFactory), factory | ||
|
||
name = factory.__class__.__name__ | ||
snake_name = obj_class_to_snake(factory) | ||
|
||
if ( | ||
name not in self._task_factories | ||
and snake_name not in self._task_factories | ||
): | ||
self._task_factories[name] = factory | ||
self._task_factories[snake_name] = factory | ||
self._task_names[factory] = [*namespaces] | ||
|
||
result = True | ||
self.logger.info( | ||
"Registered '%s' (%s) task factory.", name, snake_name | ||
) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
includes: | ||
- ports.yaml | ||
- basic_factories.yaml | ||
- tasks.yaml | ||
|
||
app: | ||
- runtimepy.net.apps.init_only | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
tasks: | ||
- {name: "a", factory: sample_task_factory_a} | ||
- {name: "b", factory: SampleTaskFactoryB, period_s: 0.1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.