Skip to content

retrieval of data after publishing a message made optional #23

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

Open
wants to merge 4 commits into
base: ente
Choose a base branch
from

Conversation

liammcalpineduckietown
Copy link
Collaborator

@liammcalpineduckietown liammcalpineduckietown commented Jul 14, 2025

This pull request refactors several modules to improve consistency in dataclass usage and updates the object queue publishing logic to better handle data retrieval and memory management. The most important changes include replacing pydantic.dataclasses.dataclass with the standard library's dataclasses.dataclass, modifying the ObjectQueue's publish method to support optional data retrieval, and optimizing how published data is stored and evicted. Additionally, related methods and usages throughout the codebase have been updated to reflect these changes.

Refactoring and Standardization

  • Replaced imports of pydantic.dataclasses.dataclass with the standard library's dataclasses.dataclass across multiple files (src/dtps_http/link_headers.py, src/dtps_http/object_queue.py, src/dtps_http/server.py, src/dtps_http/structures.py). [1] [2] [3] [4]

Object Queue Publishing Logic

  • Updated the ObjectQueue.publish method to accept a new get_data parameter, which determines whether to return the published data or just acknowledge the publish action. The default behavior now returns None unless get_data=True is specified. [1] [2]
  • Modified related publish methods (publish_text, publish_cbor, publish_json, publish_yaml) to pass get_data=True to ensure they return the published data as expected.

Data Storage and Eviction

  • Changed the stored deque in ObjectQueue to use a bounded length (maxlen=bounds.max_size) and updated the eviction logic to only remove the oldest item when the maximum size is reached, improving memory management and consistency. [1] [2]

Type and Structure Adjustments

  • Updated the PostResult type to allow None, reflecting the new optional return value from the publish method.
  • Adjusted the internal structure of ObjectQueue to rename and clarify member variables, such as using _transform instead of transform.

API Usage Updates

  • Updated all usages of ObjectQueue.publish in src/dtps_http/types_of_source.py and src/dtps/ergo_create.py to pass get_data=True, ensuring correct data retrieval after publishing. [1] [2] [3]

@liammcalpineduckietown liammcalpineduckietown force-pushed the ente-DTSW-6878-Investigate-ways-that-we-can-reduce-the-CPU-load-of-the-wheel_encoder-TOF-IMU-drivers-and-car_interface branch from 4521f1c to ee23d33 Compare July 15, 2025 17:10
@liampaull
Copy link
Member

@liammcalpineduckietown can you take a look at the conlict? How did you test this?

…reduce-the-CPU-load-of-the-wheel_encoder-TOF-IMU-drivers-and-car_interface
@liammcalpineduckietown
Copy link
Collaborator Author

@liammcalpineduckietown can you take a look at the conlict? How did you test this?

https://ethidsc.atlassian.net/browse/DTSW-6878

@Tuxliri
Copy link
Collaborator

Tuxliri commented Aug 20, 2025

This is outside of the scope of this PR but given that we have got things working decently and that dtps seems a bit flimsy I propose adding some basic automatic testing (pub-sub directly and through a switchboard) using the available examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants