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

fix: correct the way to catch the exception #1727

Merged
merged 5 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion metadata-ingestion/ldap-etl/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
avro-python3==1.8.2
confluent-kafka==1.4.0
confluent-kafka[avro]==1.4.0
python-ldap==3.2.0
2 changes: 1 addition & 1 deletion metadata-ingestion/mysql-etl/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
avro-python3==1.8.2
confluent-kafka==1.4.0
confluent-kafka[avro]==1.4.0
mysql-connector==2.2.9
18 changes: 12 additions & 6 deletions metadata-ingestion/sql-etl/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/python
import time
from uuid import uuid4

from confluent_kafka import avro
from confluent_kafka.avro import AvroProducer
Expand Down Expand Up @@ -80,21 +81,26 @@ def build_dataset_mce(platform, dataset_name, columns):
}


def delivery_report(err, msg):
""" Called once for each message produced to indicate delivery result.
Triggered by poll() or flush(). """
if err is not None:
print('Message delivery failed: {}'.format(err))
else:
print('Message delivered to {} [{}]'.format(msg.topic(), msg.partition()))


def produce_dataset_mce(mce, kafka_config):
"""
Produces a MetadataChangeEvent to Kafka
"""
conf = {'bootstrap.servers': kafka_config.bootstrap_server,
'on_delivery': delivery_report,
'schema.registry.url': kafka_config.schema_registry}
record_schema = avro.load(kafka_config.avsc_path)
producer = AvroProducer(conf, default_value_schema=record_schema)

try:
producer.produce(topic=kafka_config.kafka_topic, value=mce)
producer.poll(0)
print('\n%s has been successfully produced!\n' % mce)
except ValueError as e:
print('Message serialization failed %s' % e)
producer.produce(topic=kafka_config.kafka_topic, key=str(uuid4()), value=mce)
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually the best value for key would be the URN specified in the mce instead of a random number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I have done some modification.

producer.flush()


Expand Down
2 changes: 1 addition & 1 deletion metadata-ingestion/sql-etl/common.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
avro-python3==1.8.2
confluent-kafka==1.1.0
confluent-kafka[avro]==1.4.0
SQLAlchemy==1.3.17