Skip to content

Add basic pollers #9

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
Aug 21, 2025
Merged

Add basic pollers #9

merged 1 commit into from
Aug 21, 2025

Conversation

natemort
Copy link
Member

What changed?

  • Create skeleton Activity and Decision Pollers

Why?

  • Entrypoint to Cadence Workers

How did you test it?

  • Unit tests, tested only basic connectivity against local Cadence

Potential risks

  • None

Release notes

Documentation Changes

from typing import TypedDict


class WorkerOptions(TypedDict, total=False):
Copy link
Member

Choose a reason for hiding this comment

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

I think we would want to expose WorkerOptions to client like the go client here

Copy link
Member Author

Choose a reason for hiding this comment

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

They're included in the init.py so they can be imported like:

from cadence.worker import WorkerOptions

Copy link
Member

@timl3136 timl3136 Aug 21, 2025

Choose a reason for hiding this comment

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

I think we should not expect customer to search for WorkerOptions definition in _types package, we should define those in some public files so that it's easy for customer to understand it's usage.

self._permits = permits
self._poll = poll
self._executor = executor
self._background_tasks = set()
Copy link
Member

@shijiesheng shijiesheng Aug 21, 2025

Choose a reason for hiding this comment

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

nit: set[async.ioFuture]()

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

return

# Need to store a reference to the async task or it may be garbage collected
scheduled = asyncio.create_task(self._execute_task(task))
Copy link
Member

Choose a reason for hiding this comment

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

eventloop has run_in_executor api.

Suggested change
scheduled = asyncio.create_task(self._execute_task(task))
scheduled = asyncio.get_running_loop().run_in_executor(self._executor, self._execute_task, task)

or you can set default executor in Poller init and thus omit the first argument

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed offline and renamed. The callback will ultimately dispatch it via another component.

@natemort natemort force-pushed the poller branch 2 times, most recently from cf495f2 to 6daae1a Compare August 21, 2025 18:29
async def run(self):
await self._poller.run()

async def poll(self) -> Optional[PollForActivityTaskResponse]:
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
async def poll(self) -> Optional[PollForActivityTaskResponse]:
async def _poll(self) -> Optional[PollForActivityTaskResponse]:

else:
return None

async def execute(self, task: PollForActivityTaskResponse):
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
async def execute(self, task: PollForActivityTaskResponse):
async def _execute(self, task: PollForActivityTaskResponse):

@natemort natemort merged commit 84cbc72 into cadence-workflow:main Aug 21, 2025
1 check 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.

3 participants