mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
queue: Rename queue_json_publish to queue_json_publish_rollback_unsafe.
This commit renames the 'queue_json_publish' function to 'queue_json_publish_rollback_unsafe' to reflect the fact that it doesn't wait for the db transaction (within which it gets called, if any) to commit and sends event irrespective of commit or rollback. In most of the cases we don't want to send event in the case of rollbacks, so the caller should be aware that calling the function directly is rollback unsafe. Fixes part of #30489.
This commit is contained in:
committed by
Tim Abbott
parent
1847086044
commit
3bad36ef8c
@@ -434,7 +434,11 @@ def set_queue_client(queue_client: SimpleQueueClient | TornadoQueueClient) -> No
|
||||
thread_data.queue_client = queue_client
|
||||
|
||||
|
||||
def queue_json_publish(
|
||||
# One should generally use `queue_event_on_commit` unless there's a strong
|
||||
# reason to use `queue_json_publish_rollback_unsafe` directly, as it doesn't
|
||||
# wait for the db transaction (within which it gets called, if any) to commit
|
||||
# and sends event irrespective of commit or rollback.
|
||||
def queue_json_publish_rollback_unsafe(
|
||||
queue_name: str,
|
||||
event: dict[str, Any],
|
||||
processor: Callable[[Any], None] | None = None,
|
||||
@@ -452,7 +456,7 @@ def queue_json_publish(
|
||||
|
||||
|
||||
def queue_event_on_commit(queue_name: str, event: dict[str, Any]) -> None:
|
||||
transaction.on_commit(lambda: queue_json_publish(queue_name, event))
|
||||
transaction.on_commit(lambda: queue_json_publish_rollback_unsafe(queue_name, event))
|
||||
|
||||
|
||||
def retry_event(
|
||||
@@ -464,4 +468,4 @@ def retry_event(
|
||||
if event["failed_tries"] > MAX_REQUEST_RETRIES:
|
||||
failure_processor(event)
|
||||
else:
|
||||
queue_json_publish(queue_name, event)
|
||||
queue_json_publish_rollback_unsafe(queue_name, event)
|
||||
|
||||
Reference in New Issue
Block a user