Skip to content

Poller

Asyncio polling loop for GitHub repositories.

Polls all configured repositories concurrently, bounded by semaphore to avoid GitHub API rate limits. Issues authored by repo collaborators are skipped by default. Exponential backoff is applied on 403/429 responses.

CLASS DESCRIPTION
GitHubPoller

Polls GitHub repositories for new/updated issues on a configured interval.

Classes

GitHubPoller

GitHubPoller(token: SecretStr, memory: MemoryStore, max_concurrent: int = _DEFAULT_MAX_CONCURRENT)

Polls GitHub repositories for new/updated issues on a configured interval.

Repositories are polled concurrently using :mod:asyncio, limited by a semaphore. The last-polled timestamp for each repo is persisted so that only issues updated after that timestamp are emitted on subsequent polls.

PARAMETER DESCRIPTION
token

GitHub Personal Access Token for the bot account.

TYPE: SecretStr

memory

:class:~foreman.memory.MemoryStore used to persist poll state.

TYPE: MemoryStore

max_concurrent

Maximum number of repos polled simultaneously.

TYPE: int DEFAULT: _DEFAULT_MAX_CONCURRENT

METHOD DESCRIPTION
poll_all

Poll all repositories concurrently, respecting the semaphore limit.

poll_repo

Poll a single repository for new or updated issues.

run

Poll all repos in a continuous loop at interval_seconds frequency.

Functions

poll_all async
poll_all(repos: list[RepoConfig], callback: Callable[[RepoConfig, dict[str, Any]], Awaitable[None]]) -> None

Poll all repositories concurrently, respecting the semaphore limit.

Each repo is polled in a thread via :func:asyncio.to_thread so blocking PyGithub calls do not block the event loop. On 403/429 errors, one retry is attempted after an exponential backoff delay. Other :class:~github.GithubException errors are re-raised.

PARAMETER DESCRIPTION
repos

List of repository configs to poll this cycle.

TYPE: list[RepoConfig]

callback

Async callable invoked with (repo_config, event) for every emitted event.

TYPE: Callable[[RepoConfig, dict[str, Any]], Awaitable[None]]

poll_repo
poll_repo(repo_config: RepoConfig) -> list[dict[str, Any]]

Poll a single repository for new or updated issues.

Fetches issues updated since the last recorded poll timestamp. Issues authored by collaborators are filtered out. Persists the new poll timestamp after a successful fetch.

PARAMETER DESCRIPTION
repo_config

Configuration for the repository to poll.

TYPE: RepoConfig

RETURNS DESCRIPTION
list[dict[str, Any]]

A list of event dicts, each with repo, issue_number, and

list[dict[str, Any]]

payload keys.

RAISES DESCRIPTION
GithubException

Propagated for all GitHub API errors; the caller in :meth:poll_all handles rate-limit cases with backoff.

run async
run(repos: list[RepoConfig], interval_seconds: int, callback: Callable[[RepoConfig, dict[str, Any]], Awaitable[None]]) -> None

Poll all repos in a continuous loop at interval_seconds frequency.

PARAMETER DESCRIPTION
repos

Repositories to monitor.

TYPE: list[RepoConfig]

interval_seconds

Seconds to wait between poll cycles.

TYPE: int

callback

Async callable invoked per emitted event.

TYPE: Callable[[RepoConfig, dict[str, Any]], Awaitable[None]]