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

feat!: Switch to a single Producer, wrapped in an API singleton #32

Merged
merged 9 commits into from
Aug 31, 2022

Conversation

timmc-edx
Copy link
Contributor

@timmc-edx timmc-edx commented Aug 26, 2022

Purpose:

Relying code should now call get_producer().send(...) rather than send_to_event_bus(...). The return value is an object that wraps a Producer instance (not a SerializingProducer) and that handles the serialization itself.

Serialization logic is moved to a cached get_serializers(...) that expands upon the previous get_serializer function; it now returns a pair of key and value serializers. This also acts as a patch point for mocking.

send_to_event_bus gets a shorter name (now it's just a send method) and loses the sync keyword argument; there is instead now a pre_shutdown method.


A few refactoring changes are broken out into foundational commits to make review easier, but I might squash-merge them:

  • Cache create_schema_registry_client and rename to get_...
  • Lift producer test data to be instance variables

Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Commits are squashed
  • Noted any: Concerns, dependencies, deadlines, tickets, testing instructions

@timmc-edx timmc-edx force-pushed the timmc/single-producer branch 2 times, most recently from 71f66d0 to efad224 Compare August 26, 2022 15:20
Purpose:

- Revisit #16 since I
  finally figured out a clean way to have a single producer.
- Reduce the burden on future code that will need to adjust how polling
  is done (#31) and
  maybe handle shutdown (#11)
- Prepare for configurable implementation loading, which will need a
  singleton and getter: openedx/openedx-events#87
- Get rid of the `sync` argument (which didn't fit the abstraction) and
  move it to a dedicated method.

Relying code should now call `get_producer().send(...)` rather than
`send_to_event_bus(...)`. The return value is an object that wraps a
`Producer` instance (not a `SerializingProducer`) and that handles the
serialization itself.

Serialization logic is moved to a cached `get_serializers(...)` that
expands upon the previous `get_serializer` function; it now returns a pair
of key and value serializers. This also acts as a patch point for
mocking. I'd like to test the serializers themselves, but they want to
talk to a server.

`send_to_event_bus` gets a shorter name (now it's just a `send` method)
and loses the `sync` keyword argument; there is instead now a
`pre_shutdown` method.
@timmc-edx timmc-edx force-pushed the timmc/single-producer branch from efad224 to a4b9e52 Compare August 26, 2022 15:33
Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

Thanks @timmc-edx. I appreciated being able to review the separate commits, even if you squash in the end.

edx_event_bus_kafka/config.py Outdated Show resolved Hide resolved
edx_event_bus_kafka/config.py Outdated Show resolved Hide resolved
edx_event_bus_kafka/config.py Outdated Show resolved Hide resolved
edx_event_bus_kafka/publishing/event_producer.py Outdated Show resolved Hide resolved
edx_event_bus_kafka/publishing/event_producer.py Outdated Show resolved Hide resolved
edx_event_bus_kafka/publishing/event_producer.py Outdated Show resolved Hide resolved
- Fix comment re: client caching
- Use `cache` instead of `lru_cache` (should only ever have one value
  anyhow)
functools.cache is new in Python 3.9. :-)
Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

I know you didn't ask for re-review, so mostly just responding to comments.

edx_event_bus_kafka/config.py Outdated Show resolved Hide resolved
edx_event_bus_kafka/publishing/event_producer.py Outdated Show resolved Hide resolved
edx_event_bus_kafka/config.py Outdated Show resolved Hide resolved
edx_event_bus_kafka/publishing/event_producer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@robrap robrap left a comment

Choose a reason for hiding this comment

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

Nice. Thanks.

@timmc-edx timmc-edx merged commit fa7c4fd into main Aug 31, 2022
@timmc-edx timmc-edx deleted the timmc/single-producer branch August 31, 2022 18:31
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.

2 participants