fix(campaign): roll back rejected immediate queues
This commit is contained in:
@@ -3608,6 +3608,10 @@ def send_campaign_now_endpoint(
|
||||
)
|
||||
return SendCampaignNowResponse(result=response_result)
|
||||
except SynchronousSendRejected as exc:
|
||||
# A synchronous request stages queue state before the all-message
|
||||
# preflight can run. Rejecting that preflight must not leave work
|
||||
# eligible for a background worker when no provider effect occurred.
|
||||
session.rollback()
|
||||
audit_from_principal(
|
||||
session,
|
||||
principal,
|
||||
|
||||
@@ -622,6 +622,7 @@ def _persist_campaign_queue(
|
||||
version: CampaignVersion,
|
||||
queued: list[CampaignJob],
|
||||
delivery_mode: str,
|
||||
commit: bool = True,
|
||||
) -> None:
|
||||
if queued:
|
||||
previous_status = campaign.status
|
||||
@@ -640,7 +641,8 @@ def _persist_campaign_queue(
|
||||
version_id=version.id,
|
||||
)
|
||||
session.add(campaign)
|
||||
session.commit()
|
||||
if commit:
|
||||
session.commit()
|
||||
|
||||
|
||||
def _enqueue_campaign_jobs(queued: list[CampaignJob], *, enabled: bool) -> int:
|
||||
@@ -661,6 +663,7 @@ def queue_campaign_jobs(
|
||||
include_warnings: bool = True,
|
||||
dry_run: bool = False,
|
||||
delivery_mode: str | None = None,
|
||||
commit_queue: bool = True,
|
||||
) -> QueueCampaignResult:
|
||||
"""Move queueable DB jobs to QUEUED and optionally enqueue Celery tasks."""
|
||||
|
||||
@@ -694,6 +697,7 @@ def queue_campaign_jobs(
|
||||
version=version,
|
||||
queued=queued,
|
||||
delivery_mode=selected_delivery_mode,
|
||||
commit=commit_queue,
|
||||
)
|
||||
enqueued_count = _enqueue_campaign_jobs(
|
||||
queued,
|
||||
@@ -766,6 +770,7 @@ def send_campaign_now(
|
||||
enqueue_celery=False,
|
||||
dry_run=dry_run,
|
||||
delivery_mode=DELIVERY_MODE_SYNCHRONOUS,
|
||||
commit_queue=False,
|
||||
)
|
||||
if dry_run:
|
||||
return SendCampaignNowResult(
|
||||
@@ -802,6 +807,11 @@ def send_campaign_now(
|
||||
jobs=jobs,
|
||||
policy=synchronous_policy,
|
||||
)
|
||||
# Queue state and its inbox notification become durable only after every
|
||||
# message and the selected transport revision have passed preflight. This
|
||||
# preserves late-ack recovery without leaving rejected work eligible for a
|
||||
# background worker.
|
||||
session.commit()
|
||||
|
||||
results: list[dict[str, Any]] = []
|
||||
sent_count = 0
|
||||
|
||||
Reference in New Issue
Block a user