Skip to content

fix: adapt event listeners and dispatch to framework#1541 event API - #150

Merged
hwbrzzl merged 3 commits into
masterfrom
bowen/fix-pr-1541-event-listener-break
Sep 9, 2026
Merged

hwbrzzl merged 3 commits into
masterfrom
bowen/fix-pr-1541-event-listener-break

Conversation

@goravel-coder

@goravel-coder goravel-coder commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The example now builds and runs against framework#1541's event rework: SendShipmentNotification and the feature suite's integrationListener satisfy the new event.Listener contract (Handle(eventName string, args ...any) error), so the bundled OrderShipped/OrderCanceled demo events dispatch again.
  • Event dispatch and registration in the example service and the event feature suite now use facades.Event().Dispatch(...) / Listen(...) and the returned Result instead of the deprecated Job(...).Dispatch() / Register(...) flow; the dispatch tests assert the new semantics — an unlistened event is a silent success, and every registered listener runs with its failures aggregated into the Result rather than aborting the dispatch.
  • The event feature suite now also covers the deprecated Job/Register/GetEvents path while it remains available, locking in its legacy semantics: an unbound job fails with EventListenerNotBind, a job is fail-fast and delivers Handle-transformed payloads to sync or queued listeners, and GetEvents returns a defensive copy.

Closes https://github.com/goravel/goravel/issues/1541

Why

framework#1541 reworked the event module: event.Listener.Handle now receives the canonical event name first (Handle(eventName string, args ...any) error), and Listen/Dispatch replaced the now-deprecated Register/Job flow with a Result that joins every listener error. Once the example pinned goravel/framework past that merge, the demo listener and the suite's integrationListener no longer satisfied event.Listener, so the example would not build. This PR adapts both listeners to the new contract and migrates the example service and the event feature suite to the current Dispatch/Listen API.

// Before: the old Listener contract; no longer satisfies event.Listener after framework#1541.
func (receiver *SendShipmentNotification) Handle(args ...any) error {
	if len(args) > 0 {
		TestResultOfSendShipmentNotification = append(TestResultOfSendShipmentNotification, cast.ToString(args[0]))
	}

	return nil
}

// After: framework#1541 passes the canonical event name first; the payload still starts at args[0].
func (receiver *SendShipmentNotification) Handle(eventName string, args ...any) error {
	if len(args) > 0 {
		TestResultOfSendShipmentNotification = append(TestResultOfSendShipmentNotification, cast.ToString(args[0]))
	}

	return nil
}

Dispatch semantics changed with it: the framework now runs every matching listener and collects the failures, and an event with no listeners is a no-op rather than an error. The migrated dispatch tests assert those semantics — each registers under its own event type because Listen appends listeners by the event's type name rather than overwriting them, and the payload argument positions passed to Handle are unchanged.

// Before: dispatch went through the deprecated Job(...).Dispatch() flow.
func Event() error {
	return facades.Event().Job(&events.OrderShipped{}, []contractevent.Arg{
		{Type: "string", Value: "test"},
		{Type: "int", Value: 1234},
	}).Dispatch()
}

// After: Dispatch returns a Result whose Error() reports every listener error.
func Event() error {
	return facades.Event().Dispatch(&events.OrderShipped{}, []contractevent.Arg{
		{Type: "string", Value: "test"},
		{Type: "int", Value: 1234},
	}).Error()
}

The deprecated Register/Job/GetEvents path is still shipped and will only be removed in a future version, so the feature suite keeps it under test while it exists. The new Job-based tests pin down its legacy semantics — an unbound job fails with EventListenerNotBind, the event's Handle error short-circuits the job, a job stops at the first listener error, and it still delivers Handle-transformed arguments to both sync and queued listeners — while GetEvents is verified to hand back a defensive copy so callers cannot mutate the live registry. Keeping these tests guards the deprecated path from regressions and gives the eventual removal a defined, tested contract to migrate against.

@goravel-coder
goravel-coder requested a review from a team as a code owner September 8, 2026 04:35
@goravel-coder goravel-coder changed the title fix: adapt event listeners to new Handle signature (framework#1541) fix: adapt event listeners and dispatch to framework#1541 event API Sep 8, 2026
@hwbrzzl
hwbrzzl merged commit ef8be74 into master Sep 9, 2026
9 checks passed
@hwbrzzl
hwbrzzl deleted the bowen/fix-pr-1541-event-listener-break branch September 9, 2026 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants