@@ -245,7 +245,7 @@ def create_trigger_db(trigger_api):
245
245
return trigger_db
246
246
247
247
248
- def create_or_update_trigger_db (trigger ):
248
+ def create_or_update_trigger_db (trigger , log_not_unique_error_as_debug = False ):
249
249
"""
250
250
Create a new TriggerDB model if one doesn't exist yet or update existing
251
251
one.
@@ -269,7 +269,8 @@ def create_or_update_trigger_db(trigger):
269
269
if is_update :
270
270
trigger_db .id = existing_trigger_db .id
271
271
272
- trigger_db = Trigger .add_or_update (trigger_db )
272
+ trigger_db = Trigger .add_or_update (trigger_db ,
273
+ log_not_unique_error_as_debug = log_not_unique_error_as_debug )
273
274
274
275
extra = {'trigger_db' : trigger_db }
275
276
@@ -331,13 +332,20 @@ def cleanup_trigger_db_for_rule(rule_db):
331
332
Trigger .delete_if_unreferenced (existing_trigger_db )
332
333
333
334
334
- def create_trigger_type_db (trigger_type ):
335
+ def create_trigger_type_db (trigger_type , log_not_unique_error_as_debug = False ):
335
336
"""
336
337
Creates a trigger type db object in the db given trigger_type definition as dict.
337
338
338
339
:param trigger_type: Trigger type model.
339
340
:type trigger_type: ``dict``
340
341
342
+ :param log_not_unique_error_as_debug: True to lot NotUnique errors under debug instead of
343
+ error log level. This is to be used in scenarios where
344
+ failure is non-fatal (e.g. when services register
345
+ internal trigger types which is an idempotent
346
+ operation).
347
+ :type log_not_unique_error_as_debug: ``bool``
348
+
341
349
:rtype: ``object``
342
350
"""
343
351
trigger_type_api = TriggerTypeAPI (** trigger_type )
@@ -349,13 +357,23 @@ def create_trigger_type_db(trigger_type):
349
357
if not trigger_type_db :
350
358
trigger_type_db = TriggerTypeAPI .to_model (trigger_type_api )
351
359
LOG .debug ('verified trigger and formulated TriggerDB=%s' , trigger_type_db )
352
- trigger_type_db = TriggerType .add_or_update (trigger_type_db )
360
+ trigger_type_db = TriggerType .add_or_update (trigger_type_db ,
361
+ log_not_unique_error_as_debug = log_not_unique_error_as_debug )
362
+
353
363
return trigger_type_db
354
364
355
365
356
- def create_shadow_trigger (trigger_type_db ):
366
+ def create_shadow_trigger (trigger_type_db , log_not_unique_error_as_debug = False ):
357
367
"""
358
368
Create a shadow trigger for TriggerType with no parameters.
369
+
370
+ :param log_not_unique_error_as_debug: True to lot NotUnique errors under debug instead of
371
+ error log level. This is to be used in scenarios where
372
+ failure is non-fatal (e.g. when services register
373
+ internal trigger types which is an idempotent
374
+ operation).
375
+ :type log_not_unique_error_as_debug: ``bool``
376
+
359
377
"""
360
378
trigger_type_ref = trigger_type_db .get_reference ().ref
361
379
@@ -368,16 +386,24 @@ def create_shadow_trigger(trigger_type_db):
368
386
'type' : trigger_type_ref ,
369
387
'parameters' : {}}
370
388
371
- return create_or_update_trigger_db (trigger )
389
+ return create_or_update_trigger_db (trigger ,
390
+ log_not_unique_error_as_debug = log_not_unique_error_as_debug )
372
391
373
392
374
- def create_or_update_trigger_type_db (trigger_type ):
393
+ def create_or_update_trigger_type_db (trigger_type , log_not_unique_error_as_debug = False ):
375
394
"""
376
395
Create or update a trigger type db object in the db given trigger_type definition as dict.
377
396
378
397
:param trigger_type: Trigger type model.
379
398
:type trigger_type: ``dict``
380
399
400
+ :param log_not_unique_error_as_debug: True to lot NotUnique errors under debug instead of
401
+ error log level. This is to be used in scenarios where
402
+ failure is non-fatal (e.g. when services register
403
+ internal trigger types which is an idempotent
404
+ operation).
405
+ :type log_not_unique_error_as_debug: ``bool``
406
+
381
407
:rtype: ``object``
382
408
"""
383
409
assert isinstance (trigger_type , dict )
@@ -399,7 +425,8 @@ def create_or_update_trigger_type_db(trigger_type):
399
425
trigger_type_api .id = existing_trigger_type_db .id
400
426
401
427
try :
402
- trigger_type_db = TriggerType .add_or_update (trigger_type_api )
428
+ trigger_type_db = TriggerType .add_or_update (trigger_type_api ,
429
+ log_not_unique_error_as_debug = log_not_unique_error_as_debug )
403
430
except StackStormDBObjectConflictError :
404
431
# Operation is idempotent and trigger could have already been created by
405
432
# another process. Ignore object already exists because it simply means
0 commit comments