thin-edge / thin-edge.io

The open edge framework for lightweight IoT devices
https://thin-edge.io
Apache License 2.0
211 stars 55 forks source link

Simplify the operation handling code by replacing fragmented control flow with regular async/await #2880

Open Bravo555 opened 1 month ago

Bravo555 commented 1 month ago

Is your refactoring request related to a problem? Please describe.

As originally described in the Further Comments section in the PR about using the File Transfer Service for log and config operations, the current architecture of the C8y mapper actor adds unnecessary complexity to the operation handling code, by:

This:

It concerns mainly the interaction between downloader and uploader actors, where every time we need to download/upload from within the operation, we need to send the request and return, in order not to block handling of other things.

Describe the solution you'd like

The preferred solution would be to handle the entirety of an operation in a module dedicated to that operation, without returning, saving state, and relying on other parts of the code to continue the execution. We should be able to run the future that handles the operation concurrently, as that's what async/await should allow.

This was already done for c8y_firmware_manager (https://github.com/thin-edge/thin-edge.io/pull/2600), now the aim would be to do something similar with c8y_mapper_ext and its operation handling.

Describe alternatives you've considered

Additional context