Skip to content

polling: support header_factory for per-poll token refresh#123

Merged
absoludity merged 4 commits into
masterfrom
53-polling-token-refresh
Mar 25, 2026
Merged

polling: support header_factory for per-poll token refresh#123
absoludity merged 4 commits into
masterfrom
53-polling-token-refresh

Conversation

@absoludity
Copy link
Copy Markdown
Collaborator

@absoludity absoludity commented Mar 25, 2026

Summary

  • Adds optional header_factory: Callable[[], Awaitable[dict[str, str]]] | None parameter to HttpPollerService.__init__()
  • On each poll_endpoint() call, if a factory is set it is called and its headers are merged over any static headers in PollingConfig.connection_params (factory wins on conflict)
  • No changes to PollingConfig or the PollerService protocol — fully backwards compatible

Motivation

Auth headers embedded in PollingConfig at setup time expire with the OAuth2 token (15–60 min), causing all subsequent polls to fail with 401. Since PollingConfig is serialised as JSON by Temporal, it cannot carry a callable — the factory lives in the activity (worker process) instead.

Fixes #53

Test plan

  • test_poll_endpoint_uses_header_factory_when_set — factory called, headers override config
  • test_poll_endpoint_skips_header_factory_when_none — no factory, config headers unchanged
  • All existing tests pass

@absoludity absoludity requested a review from monkeypants March 25, 2026 03:15
@absoludity
Copy link
Copy Markdown
Collaborator Author

I'll be landing this current series of julee branches tomorrow (more doctrine + crud generation) so I can properly fix the rba e2e tests.

@absoludity absoludity force-pushed the 91-generated-CRUD-1 branch from 8c1a0dd to 1ed5f91 Compare March 25, 2026 23:22
@absoludity absoludity changed the base branch from 91-generated-CRUD-1 to master March 25, 2026 23:22
HttpPollerService accepts an optional header_factory callable that is
invoked on every poll_endpoint() call. The returned headers are merged
over any static headers in PollingConfig.connection_params, with factory
headers taking precedence.

This allows consumers to supply a fresh OAuth2 token on each poll without
storing the token (or any callable) in PollingConfig, which Temporal
serialises as JSON and cannot carry callables.
@absoludity absoludity force-pushed the 53-polling-token-refresh branch from bc5a867 to 712657f Compare March 25, 2026 23:23
@absoludity absoludity merged commit 57d6cfe into master Mar 25, 2026
3 checks passed
@absoludity absoludity deleted the 53-polling-token-refresh branch March 25, 2026 23:23
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.

polling: Enable token refresh in polling contrib app

1 participant