Skip to content

Allow to set custom periodic names #224

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

Merged
merged 1 commit into from
Apr 1, 2025

Conversation

mosquito
Copy link
Collaborator

@mosquito mosquito commented Apr 1, 2025

Add name parameter to RecurringCallback and PeriodicService

Changes:

  • Added optional name parameter to RecurringCallback.init
  • Falls back to function repr if name not provided
  • Added name parameter to PeriodicService.init
  • Passes name through to underlying PeriodicCallback

Impact:

  • Allows better identification of callbacks in logs/metrics
  • Maintains backward compatibility

@mosquito mosquito requested a review from Copilot April 1, 2025 10:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a custom name parameter to the RecurringCallback and PeriodicService classes in order to facilitate improved identification of callbacks in logs and metrics while preserving backward compatibility.

  • Added an optional name parameter to RecurringCallback.init with fallback to repr(coroutine_func).
  • Added an optional name parameter to PeriodicService.init and passed it through to PeriodicCallback.
  • Ensured that changes maintain backward compatibility.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
aiomisc/service/periodic.py Updated init to accept a name parameter and pass it through to PeriodicCallback.
aiomisc/recurring.py Updated init to accept a name parameter and set self.name using the provided name or a fallback value.
Comments suppressed due to low confidence (2)

aiomisc/service/periodic.py:20

  • Ensure tests are added to verify that the 'name' parameter is correctly passed to PeriodicCallback and handled when provided as well as when it is omitted.
self.periodic = PeriodicCallback(self.callback, name=name)

aiomisc/recurring.py:58

  • Please add tests to confirm that the proper name is set, verifying both cases when a custom name is provided and when the fallback to repr(coroutine_func) is used.
self.name: str = name or repr(coroutine_func)

@mosquito mosquito merged commit 7c4ef78 into master Apr 1, 2025
30 of 31 checks passed
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.

1 participant