Use partial instead of lambda when queuing ack task (#3134)
Prefer partial since it is the what the [docs suggests](https://docs.djangoproject.com/en/4.2/topics/db/transactions/#performing-actions-after-commit). Also because partial is evaluated immediately while lambda is evaluated at runtime (which may be causing some issues): ``` >>> from functools import partial >>> def foo(a, b, c): ... print(a, b, c) ... >>> x = 10 >>> bar_partial = partial(foo, 1, 2, x) >>> bar_lambda = lambda: foo(1, 2, x) >>> x = 20 >>> bar_partial() 1 2 10 >>> bar_lambda() 1 2 20 ```
This commit is contained in:
parent
525c963fc6
commit
88f9f118a3
1 changed files with 4 additions and 2 deletions
|
|
@ -1,3 +1,5 @@
|
|||
from functools import partial
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import transaction
|
||||
|
||||
|
|
@ -60,7 +62,7 @@ def acknowledge_reminder_task(alert_group_pk: int, unacknowledge_process_id: str
|
|||
log_record = alert_group.log_records.create(
|
||||
type=AlertGroupLogRecord.TYPE_ACK_REMINDER_TRIGGERED, author=alert_group.acknowledged_by_user
|
||||
)
|
||||
transaction.on_commit(lambda: send_alert_group_signal.delay(log_record.pk))
|
||||
transaction.on_commit(partial(send_alert_group_signal.delay, log_record.pk))
|
||||
|
||||
|
||||
@shared_dedicated_queue_retry_task(autoretry_for=(Exception,), retry_backoff=True, max_retries=MAX_RETRIES)
|
||||
|
|
@ -108,6 +110,6 @@ def unacknowledge_timeout_task(alert_group_pk: int, unacknowledge_process_id: st
|
|||
log_record = alert_group.log_records.create(
|
||||
type=AlertGroupLogRecord.TYPE_AUTO_UN_ACK, author=alert_group.acknowledged_by_user
|
||||
)
|
||||
transaction.on_commit(lambda: send_alert_group_signal.delay(log_record.pk))
|
||||
transaction.on_commit(partial(send_alert_group_signal.delay, log_record.pk))
|
||||
alert_group.unacknowledge()
|
||||
alert_group.start_escalation_if_needed()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue