-
Notifications
You must be signed in to change notification settings - Fork 20
Description
Expected Behaviour
Adaptors running as a daemon should properly pass along openjd_progress and openjd_status messages to the frontend runner.
Current Behaviour
Adaptors using run will work and spit out the proper openjd_progress/openjd_status messages, but daemon run print out nothing since the background process
Reproduction Steps
Here's an the integ adaptor with modifying it to call update_status(progress=0) and update_status(progress=100)
run:
I(openjd-adaptor-runtime) bash-3.2$ python -m integ.AdaptorExample run --run-data '{"hello": "world"}'
...
INFO: on_run: {'hello': 'world'}
openjd_progress: 0
...
STDOUT: Performing action: {"name": "print", "args": {"message": "`on_run` is called with run_data: {'hello': 'world'}"}}
STDOUT: App: `on_run` is called with run_data: {'hello': 'world'}
openjd_progress: 100
...
However, when run as a daemon, nothing is hooked up to the stdout. So we're piping the messages nowhere instead of the log.
daemon run:
(openjd-adaptor-runtime) bash-3.2$ python -m integ.AdaptorExample daemon run --connection-file ./AdaptorExampleConnection.json --run-data '{"hello": "world"}'
INFO: Applying user-level configuration: /Users/morgane/.openjd/worker/adaptors/runtime/configuration.json
INFO: Applying user-level configuration: /Users/morgane/.openjd/adaptors/AdaptorExample/AdaptorExample.json
ADAPTOR_OUTPUT:
ADAPTOR_OUTPUT: INFO: on_run: {'hello': 'world'}
ADAPTOR_OUTPUT: STDOUT: Performing action: {"name": "print", "args": {"message": "`on_run` is called with run_data: {'hello': 'world'}"}}
ADAPTOR_OUTPUT: STDOUT: App: `on_run` is called with run_data: {'hello': 'world'}
ADAPTOR_OUTPUT: STDOUT: Performing action: {"name": "print", "args": {"message": "`on_run` is finished."}}
ADAPTOR_OUTPUT: STDOUT: App: `on_run` is finished.
Code Snippet
openjd-adaptor-runtime-for-python/src/openjd/adaptor_runtime/adaptors/_base_adaptor.py
Lines 185 to 205 in 0732e4a
| def update_status( | |
| cls, *, progress: float | None = None, status_message: str | None = None | |
| ) -> None: | |
| """Using OpenJD stdout prefixes the adaptor will notify the | |
| Worker Agent about the progress, status message, or both""" | |
| if progress is None and status_message is None: | |
| _logger.warning("Both progress and status message were None. Ignoring status update.") | |
| return | |
| if progress is not None: | |
| if math.isfinite(progress): | |
| sys.stdout.write(f"{cls._OPENJD_PROGRESS_STDOUT_PREFIX}{progress}{os.linesep}") | |
| sys.stdout.flush() | |
| else: | |
| _logger.warning( | |
| f"Attempted to set progress to something non-finite: {progress}. " | |
| "Ignoring progress update." | |
| ) | |
| if status_message is not None: | |
| sys.stdout.write(f"{cls._OPENJD_STATUS_STDOUT_PREFIX}{status_message}{os.linesep}") | |
| sys.stdout.flush() |
This should be going to the log buffer if it's running as a daemon, but we should ensure it continues to work with a normal run. logging might automatically add a prefix, so we may need to control these specific logs.