Skip to content
Draft
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
17 changes: 14 additions & 3 deletions juturna/cli/commands/_juturna_remote_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import threading
import time
import itertools

from concurrent import futures

from juturna.components import Message, Node
from juturna.payloads import ControlPayload, ControlSignal


import grpc

from juturna.components import Message, Node
from juturna.remotizer._remote_context import RequestContext
from juturna.remotizer._remote_builder import _standalone_builder

Expand Down Expand Up @@ -168,9 +170,18 @@ def SendAndReceive(self, request: ProtoEnvelope, context):
request_message.id = tracking_id

if envelope_dict.get('configuration'):
_configuration_to_be_applied = envelope_dict.get(
configuration_to_be_applied = envelope_dict.get(
'configuration', {}
)
configuration_message = Message(
creator=self.remote_name,
version=request_message.version,
payload=ControlPayload(
signal=ControlSignal.CONFIGURE,
data=configuration_to_be_applied,
),
)
self.node.put(configuration_message)

request_message._freeze()
self.node.put(request_message)
Expand Down
14 changes: 14 additions & 0 deletions juturna/components/_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ def configure(self): ...

def update(self, message: Message[T_Input]): ...

def update_config(self, config: dict): ...

def reset_config(self): ...

def set_on_config(self, prop: str, value: Any): ...

def warmup(self): ...
Expand Down Expand Up @@ -527,6 +531,16 @@ def _control(self, message: Message):
self._suspended = False
self._logger.info('node resumed')

return
case ControlSignal.CONFIGURE:
self.update_config(message.payload.data)
self._logger.info('node reconfigured')

return
case ControlSignal.RESET:
self.reset_config()
self._logger.info('node reset')

return
case None:
return
Expand Down
2 changes: 2 additions & 0 deletions juturna/payloads/_control_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ class ControlSignal(IntEnum):
WARMUP: int = 2
SUSPEND: int = 3
RESUME: int = 4
CONFIGURE: int = 5
RESET: int = 6
1 change: 1 addition & 0 deletions juturna/payloads/_payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def serialize(obj):
@dataclass(frozen=True)
class ControlPayload(BasePayload):
signal: ControlSignal = ControlSignal.STOP
data: dict = field(default_factory=dict)


@dataclass(frozen=True)
Expand Down
1 change: 1 addition & 0 deletions juturna/remotizer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def deserialize_envelope(envelope: ProtoEnvelope) -> dict[str, Any]:
'ttl': envelope.ttl,
'request_type': envelope.request_type,
'response_type': envelope.response_type,
'configuration': dict(envelope.configuration),
'message': message,
}
return envelope_dict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def __init__(self, delay: int, **kwargs):
self._delay = delay
self._transmitted = 0

def update_config(self, config: dict):
"""Update the node configuration"""
if 'delay' in config:
self._delay = config['delay']
self.logger.info(
f'config updated: delay set to {self._delay} seconds'
)

def update(self, message: Message[BasePayload]):
"""Receive a message from downstream, transmit a message upstream"""
self.logger.info(
Expand Down
Loading