Skip to content
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

Use a dataclass or NamedTuple for DispatchingActor._scheduled_events items #58

Open
llucax opened this issue Sep 25, 2024 · 0 comments
Open
Labels
part:actor Affects the dispatching actor type:tech-debt Improves the project without visible changes for users

Comments

@llucax
Copy link
Contributor

llucax commented Sep 25, 2024

What's needed?

We need to make the code more naturally readable, as expressions like:

                _logger.debug(
                    "Executing scheduled event: %s", self._scheduled_events[0][1]
                )
                await self._execute_scheduled_event(heappop(self._scheduled_events)[1])
...
            _logger.debug("Next event scheduled at %s", self._scheduled_events[0][0])

are not super readable.

Proposed solution

Instead of tuple[datetime, Dispatch], use something like:

from typing import NamedTuple

class ScheduledDispatchEvent(NamedTuple):
    event_time: datetime
    dispatch: Dispatch

So such expressions can become at least:

                _logger.debug(
                    "Executing scheduled event for dispatch: %s", self._scheduled_events[0].dispatch
                )
                await self._execute_scheduled_event(heappop(self._scheduled_events).dispatch)
...
            _logger.debug("Next event scheduled at %s", self._scheduled_events[0].event_time)
@llucax llucax added type:tech-debt Improves the project without visible changes for users part:actor Affects the dispatching actor labels Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
part:actor Affects the dispatching actor type:tech-debt Improves the project without visible changes for users
Projects
None yet
Development

No branches or pull requests

1 participant