Skip to content

Commit

Permalink
fix(kafka producer init): Handle missing args.dry_run without throwin…
Browse files Browse the repository at this point in the history
…g an exception
  • Loading branch information
Smejky338 committed Feb 15, 2024
1 parent f3e5ddc commit 343b185
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions opl/kafka_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import kafka
from kafka import KafkaProducer, KafkaConsumer

# from . import status_data
import logging
Expand All @@ -7,12 +7,14 @@


def kafka_bootstrap(args):
if args.kafka_bootstrap:
try:
return args.kafka_bootstrap
if args.kafka_hosts != None and args.kafka_hosts != "":
return args.kafka_hosts.split(",")
else:
return f"{args.kafka_host}:{args.kafka_port}"
except AttributeError:
try:
if args.kafka_hosts != "":
return args.kafka_hosts.split(",")
except AttributeError:
return f"{args.kafka_host}:{args.kafka_port}"


# Based on the args, obtain KafkaProducer instance
Expand All @@ -23,7 +25,7 @@ def get_producer(args, status_data=None):
if args.kafka_acks != "all":
args.kafka_acks = int(args.kafka_acks)

if args.dry_run:
if hasattr(args, "dry_run") and args.dry_run:
logging.info(f"NOT creating a producer as this is a dry run")
producer = None
else:
Expand Down

0 comments on commit 343b185

Please sign in to comment.