Closed mperham closed 4 years ago
fwg's middleware is meant to provide a Context that the user can use to setup contextual data for the given job:
func SetupContext(ctx worker.Context, job *faktory.Job) error { aid := job.GetCustom("account_id") uid := job.GetCustom("user_id") ctx.WithValue("aid", aid).WithValue("uid", uid) return nil } mgr.Use(SetupContext)
But WithValue returns a copy of the context and it's impossible to pass on the new copy to the job execution. We'll likely need to adjust the Middleware API to something like this:
WithValue
func SetupContext(ctx worker.Context, job *faktory.Job) (Context, error) { ... return ctx.WithValue("aid", aid).WithValue("uid", uid), nil }
so that modified Contexts can be passed along the chain.
Now I can use context to set the value after https://github.com/contribsys/faktory_worker_go/commit/490cb2a66d8cdc6b8f2aafb7d0a88d6edbd7a82d.
We can close this. @mperham Thanks
fwg's middleware is meant to provide a Context that the user can use to setup contextual data for the given job:
But
WithValue
returns a copy of the context and it's impossible to pass on the new copy to the job execution. We'll likely need to adjust the Middleware API to something like this:so that modified Contexts can be passed along the chain.