Skip to content

feat: add per-event retry and backoff for queued broadcasts - #1529

Merged
hwbrzzl merged 2 commits into
masterfrom
feat/broadcast-job-retry
Aug 3, 2026
Merged

feat: add per-event retry and backoff for queued broadcasts#1529
hwbrzzl merged 2 commits into
masterfrom
feat/broadcast-job-retry

Conversation

@goravel-coder

Copy link
Copy Markdown
Contributor

Summary

  • Queued broadcasts can now declare a per-event retry policy: BroadcastTries() sets the maximum attempts and BroadcastBackoff() sets the delay before each retry.
  • BroadcastJob now implements queue.JobWithShouldRetry, so retries are driven by the event's own policy instead of the queue worker's global tries config; broadcasts without BroadcastTries remain single-shot.
  • Added the ShouldBroadcastWithTries / ShouldBroadcastWithBackoff optional event interfaces (with regenerated mocks) so the retry policy is captured at dispatch time and enforced at execution time.

Why

Previously a queued broadcast's retry behavior was fixed by the queue worker's global tries setting, giving every broadcast job the same retry count and no way to schedule per-attempt delays. This made transient driver failures (e.g. a briefly-unavailable Pusher/Redis connection) hard to handle: either everything retried aggressively or nothing did, with no backoff between attempts.

This change lets each broadcast event opt into its own retry policy at the dispatch site, mirroring how Goravel already lets events control their queue, connections, delay, timeout, and sync/async behavior. Backoff is applied per attempt with the last value repeating, matching Laravel's backoff semantics. Events that do not implement the new interfaces keep the existing single-shot behavior, so this is fully backward compatible.

type OrderShippedBroadcast struct {
	OrderData map[string]any
}

func (e *OrderShippedBroadcast) BroadcastOn() []contracts.Channel {
	return []contracts.Channel{broadcasting.PublicChannel("orders")}
}

func (e *OrderShippedBroadcast) BroadcastAs() string {
	return "order.shipped"
}

func (e *OrderShippedBroadcast) BroadcastWith() map[string]any {
	return map[string]any{"order": e.OrderData}
}

func (e *OrderShippedBroadcast) BroadcastWhen() bool {
	return true
}

// Retry up to 3 times; wait 1s, then 2s before the remaining attempts.
func (e *OrderShippedBroadcast) BroadcastTries() int {
	return 3
}

func (e *OrderShippedBroadcast) BroadcastBackoff() []time.Duration {
	return []time.Duration{time.Second, 2 * time.Second}
}

hwbrzzl added 2 commits August 2, 2026 16:56
Implements queue.JobWithShouldRetry on BroadcastJob using the event's
BroadcastTries/BroadcastBackoff captured at dispatch time. Broadcasts
without BroadcastTries remain single-shot regardless of the worker's
tries config.
@goravel-coder
goravel-coder requested a review from a team as a code owner August 2, 2026 08:57
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.18182% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.79%. Comparing base (0c23dc0) to head (2aa82fd).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
broadcasting/job.go 91.42% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1529      +/-   ##
==========================================
- Coverage   69.81%   69.79%   -0.02%     
==========================================
  Files         396      409      +13     
  Lines       30761    31344     +583     
==========================================
+ Hits        21476    21877     +401     
- Misses       8278     8435     +157     
- Partials     1007     1032      +25     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hwbrzzl
hwbrzzl merged commit 9137d76 into master Aug 3, 2026
20 of 21 checks passed
@hwbrzzl
hwbrzzl deleted the feat/broadcast-job-retry branch August 3, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants