fixbug: The assumption that messages in 'memory' have been processed has been revoked.

This commit is contained in:
莘权 马 2023-11-30 19:20:53 +08:00
parent 6f3d1d6f5e
commit 269eee4643
2 changed files with 5 additions and 2 deletions

View file

@ -50,3 +50,6 @@ class ProductManager(Role):
else:
self._set_state(0)
return self._rc.todo
async def _observe(self, ignore_memory=False) -> int:
return await super(ProductManager, self)._observe(ignore_memory=True)

View file

@ -218,12 +218,12 @@ class Role:
return msg
async def _observe(self) -> int:
async def _observe(self, ignore_memory=False) -> int:
"""Prepare new messages for processing from the message buffer and other sources."""
# Read unprocessed messages from the msg buffer.
news = self._rc.msg_buffer.pop_all()
# Store the read messages in your own memory to prevent duplicate processing.
old_messages = self._rc.memory.get()
old_messages = [] if ignore_memory else self._rc.memory.get()
self._rc.memory.add_batch(news)
# Filter out messages of interest.
self._rc.news = [n for n in news if n.cause_by in self._rc.watch and n not in old_messages]