@@ -13,7 +13,6 @@ import (
1313 "github.com/NdoleStudio/httpsms/pkg/telemetry"
1414 cloudevents "github.com/cloudevents/sdk-go/v2"
1515 "github.com/palantir/stacktrace"
16- "github.com/google/uuid"
1716)
1817
1918// EventDispatcher dispatches a new event
@@ -73,30 +72,15 @@ func (dispatcher *EventDispatcher) DispatchWithTimeout(ctx context.Context, even
7372 return queueID , dispatcher .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
7473 }
7574
76- if dispatcher .queue == nil {
77- ctxLogger := dispatcher .tracer .CtxLogger (dispatcher .logger , span )
78- queueID := uuid .New ()
79- go func () {
80- time .Sleep (timeout )
81- dispatcher .DispatchSync (ctx , event )
82- }()
83- ctxLogger .Info (fmt .Sprintf (
84- "item added to [%s] queue with id [%s] and schedule [%s]" ,
85- dispatcher .queueConfig .Name ,
86- queueID ,
87- time .Now ().UTC ().Add (timeout ),
88- ))
89- } else {
90- task , err := dispatcher .createCloudTask (event )
91- if err != nil {
92- msg := fmt .Sprintf ("cannot create cloud task for event [%s] with id [%s]" , event .Type (), event .ID ())
93- return queueID , dispatcher .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
94- }
95-
96- if queueID , err = dispatcher .queue .Enqueue (ctx , task , timeout ); err != nil {
97- msg := fmt .Sprintf ("cannot enqueue event with ID [%s] and type [%s]" , event .ID (), event .Type ())
98- return queueID , dispatcher .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
99- }
75+ task , err := dispatcher .createCloudTask (event )
76+ if err != nil {
77+ msg := fmt .Sprintf ("cannot create cloud task for event [%s] with id [%s]" , event .Type (), event .ID ())
78+ return queueID , dispatcher .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
79+ }
80+
81+ if queueID , err = dispatcher .queue .Enqueue (ctx , task , timeout ); err != nil {
82+ msg := fmt .Sprintf ("cannot enqueue event with ID [%s] and type [%s]" , event .ID (), event .Type ())
83+ return queueID , dispatcher .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
10084 }
10185
10286 return queueID , nil
0 commit comments