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

Add optional connector connect success and failure callbacks #708

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tim-quix
Copy link
Contributor

@tim-quix tim-quix commented Jan 14, 2025

What

Provides the ability to add an optional callback for a connection attempt with a connector.

NOTE: There are defaults that use our desired Quix Cloud log output.

A setup_client method is now an additional requirement when constructing a new connector template.

How to Use

This feature is fully backwards compatible: usage does not change for users who do not wish to use the callback.

To use it, the pattern is the same across all sources and sinks:

from quixstreams.sinks.core.influxdb3 import InfluxDB3Sink

def client_connect_success_cb():
    print(f"CONNECTED!")

def client_connect_failure_cb(error):
    print(f"ERROR!")
    raise error

influxdb_sink = InfluxDB3Sink(
    token="BAD TOKEN",
    host="my host",
    ...,
    client_connect_success_cb=client_connect_success_cb,
    client_connect_failure_cb=client_connect_failure_cb,
)

Other things:

  • standardized some things like attributes across sources and sinks
  • added minor things in order to test connections as expected (some client setups do not connect it immediately)
  • fixed a few bugs here n' there

Copy link
Contributor

@gwaramadze gwaramadze left a comment

Choose a reason for hiding this comment

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

A fistful of comments.

quixstreams/sinks/base/sink.py Outdated Show resolved Hide resolved
quixstreams/sinks/base/sink.py Outdated Show resolved Hide resolved
quixstreams/sinks/base/sink.py Outdated Show resolved Hide resolved
quixstreams/sinks/community/bigquery.py Outdated Show resolved Hide resolved
Copy link
Contributor

@gwaramadze gwaramadze left a comment

Choose a reason for hiding this comment

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

I like the change😉

I'm still rather against locking on the "client" word, but it's just a name, not a big blocker.

A separate problem I see here is the fact that we don't really test community connectors and I see a ton of changes. A tad too much to be confident that everything will click 🙈

quixstreams/sinks/base/sink.py Outdated Show resolved Hide resolved
quixstreams/sinks/community/file/sink.py Outdated Show resolved Hide resolved
quixstreams/sinks/community/iceberg.py Outdated Show resolved Hide resolved
quixstreams/sinks/community/file/sink.py Outdated Show resolved Hide resolved
quixstreams/sinks/community/redis.py Show resolved Hide resolved
@@ -11,7 +11,7 @@

logger = logging.getLogger(__name__)

__all__ = ("BaseSource", "Source", "StatefulSource")
ClientConnectCallback = Optional[Callable[[Optional[Exception]], None]]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is defined twice. I just realized we don't have a place for a common source/sink code 🤔
Not sure where to put it. Did you think about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was thinking we could maybe put something in our quixstreams/utils, or maybe a new file or folder in root like quixstreams/connector-utils,

Maybe right now we aren't at the tipping point for common code quite yet, but it did cross my mind for sure.

We also run into similar things with the various connection patterns across all the sources/sinks. Lots of duplicated code here n' there.

@tim-quix tim-quix changed the title Add connector connection callback option Add optional connector connect success and failure callbacks Jan 24, 2025
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