-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Provide context.Context via goka.Context #151
Comments
I agree that we need to pass the Another problem of extending the Do you think that returning the context with |
You're right about the conflict in the method name! If backward compatibility is not an issue,
I think this kind of change would be the least destructive. |
I forgot to mention that step 0 would be to insert processor's |
Steps 0 and 1 are very easy, I can quickly build them. But I am not very sure how one would use the Looking forward, after closing this ticket with a non-destructive solution, I'd suggest we start discussing how the callback interface could be redesigned. We can plan an API breaking release if we pack enough changes together, for example, #108. |
For example I commonly implement the handling in some sort of service type, and then wrap it inside Here is a rough example: func NewProcessor(brokers []string, svc *FooService, opts ...goka.ProcessorOption) {
goka.DefineGroup("group", goka.Input("topic1", new(myCodec), func(ctx goka.Context, message interface{}) {
// Here is when we could derive context if needed...
stdctx := addTracingInformationOrAnythingElse(ctx.Context())
ctx = ctx.WithContext(stdctx)
if err := svc.HandleFooMessage(ctx, message.(*FooMessage)); err != nil {
// Sometimes not all errors should trigger panic, so we can handle this specific errors in one place here if needed.
// ...
ctx.Fail(err)
}
}))
}
type FooService struct {
Log Logger
DB Database
Client SomeHTTPClient
// ...
}
type FooMessage struct {
FieldOne string
FieldTwo string
// ...
}
func (fs *FooService) HandleFooMessage(ctx goka.Context, message *FooMessage) error {
// Here is where one could use the underlying context.
fs.Client.Do(ctx.Context(), "rest of parameters here")
// Handle specific type of *FooMessage.
// Don't use ctx.Fail here, and instead return normal error.
// This is more portable and easier to test if needed to test only the logic.
return nil
} |
Totally agree on that. We could group enough breaking changes before doing them.
|
Let's close this and have another discussion if the issue comes up again. |
Oftentimes during message processing firing another IO operation is needed (like querying a remote database, or executing remote HTTP call, or similar). Normally these IO operation would accept
context.Context
for cancellation.It would be great if Goka could propagate the context passed to processor's
Run
method to the actual callback.One of the way to do it in a backward-compatible way could be embedding
context.Context
interface insidegoka.Context
directly, so thatgoka.Context
satisfiescontext.Context
. Then one could passgoka.Context
directly to the IO function or/and create childcontext.Context
off of it.My only concern about it is that
goka.Context
would do even more things, and it's already doing a lot. But as a benefit of this solution we could avoid confusion betweencontext.Context
andgoka.Context
as use ofcontext.Context
is becoming more wide in the community.The text was updated successfully, but these errors were encountered: