@@ -371,6 +371,7 @@ def create_topics(
371
371
topics : List [Topic ],
372
372
timeout : Optional [float ] = None ,
373
373
finalize_timeout : Optional [float ] = None ,
374
+ prepend : bool = True ,
374
375
):
375
376
"""
376
377
Create topics in a Quix cluster.
@@ -379,17 +380,18 @@ def create_topics(
379
380
:param timeout: response timeout (seconds); Default 30
380
381
:param finalize_timeout: topic finalization timeout (seconds); Default 60
381
382
marked as "Ready" (and thus ready to produce to/consume from).
383
+ :param prepend: whether to prepend workspace_id during creation attempt.
382
384
"""
383
385
logger .info ("Attempting to create topics..." )
384
386
current_topics = {t ["id" ]: t for t in self .get_topics (timeout = timeout )}
385
387
finalize = set ()
386
388
for topic in topics :
387
- topic_name = self .prepend_workspace_id (topic .name )
388
- exists = self . prepend_workspace_id ( topic_name ) in current_topics
389
- if not exists or current_topics [topic_name ]["status" ] != "Ready" :
389
+ name = self .prepend_workspace_id (topic .name ) if prepend else topic . name
390
+ exists = name in current_topics
391
+ if not exists or current_topics [name ]["status" ] != "Ready" :
390
392
if exists :
391
393
logger .debug (
392
- f"Topic { self .strip_workspace_id_prefix (topic_name )} exists but does "
394
+ f"Topic { self .strip_workspace_id_prefix (name )} exists but does "
393
395
f"not have 'Ready' status. Added to finalize check."
394
396
)
395
397
else :
@@ -398,14 +400,14 @@ def create_topics(
398
400
# TODO: more robust error handling to better identify issues
399
401
# See how it's handled in the admin client and maybe consolidate
400
402
# logic via TopicManager
401
- except HTTPError as e :
403
+ except QuixApiRequestFailure as e :
402
404
# Topic was maybe created by another instance
403
- if "already exists" not in e .response . text :
405
+ if "already exists" not in e .error_text :
404
406
raise
405
- finalize .add (topic_name )
407
+ finalize .add (name )
406
408
else :
407
409
logger .debug (
408
- f"Topic { self .strip_workspace_id_prefix (topic_name )} exists and is Ready"
410
+ f"Topic { self .strip_workspace_id_prefix (name )} exists and is Ready"
409
411
)
410
412
logger .info (
411
413
"Topic creations acknowledged; waiting for 'Ready' statuses..."
0 commit comments