From 49b08ab77cc688dbb092563bb038827403c921ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Lagerstr=C3=B6m?= Date: Wed, 15 Oct 2025 09:40:13 +0200 Subject: [PATCH 1/3] add Celery task ID to the context To make it possible for the consumer of the message to see the task ID of the given task. This is necessary when interacting with flower for example. --- celery.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/celery.go b/celery.go index 5b06447..6e31659 100644 --- a/celery.go +++ b/celery.go @@ -286,6 +286,7 @@ type contextKey int const ( // ContextKeyTaskName is a context key to access task names. ContextKeyTaskName contextKey = iota + ContextKeyTaskId ) // executeTask calls the task function with args and kwargs from the message. @@ -304,6 +305,7 @@ func (a *App) executeTask(ctx context.Context, m *protocol.Task) (err error) { } ctx = context.WithValue(ctx, ContextKeyTaskName, m.Name) + ctx = context.WithValue(ctx, ContextKeyTaskId, m.ID) p := NewTaskParam(m.Args, m.Kwargs) return task(ctx, p) } From a784ff0ba717d76cc4f2575ae6011fb9b1a89ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Lagerstr=C3=B6m?= Date: Wed, 15 Oct 2025 19:35:13 +0200 Subject: [PATCH 2/3] update the name of the context task id key and add comment --- celery.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/celery.go b/celery.go index 6e31659..ee4ee9c 100644 --- a/celery.go +++ b/celery.go @@ -286,7 +286,8 @@ type contextKey int const ( // ContextKeyTaskName is a context key to access task names. ContextKeyTaskName contextKey = iota - ContextKeyTaskId + // ContextKeyTaskID is a context key to access task IDs. + ContextKeyTaskID ) // executeTask calls the task function with args and kwargs from the message. From 1f0b7c7e39e639adcad26a1a9ba9d3e9a3c4f891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Lagerstr=C3=B6m?= Date: Wed, 15 Oct 2025 19:37:02 +0200 Subject: [PATCH 3/3] updates context name when setting the value --- celery.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/celery.go b/celery.go index ee4ee9c..7288cfe 100644 --- a/celery.go +++ b/celery.go @@ -306,7 +306,7 @@ func (a *App) executeTask(ctx context.Context, m *protocol.Task) (err error) { } ctx = context.WithValue(ctx, ContextKeyTaskName, m.Name) - ctx = context.WithValue(ctx, ContextKeyTaskId, m.ID) + ctx = context.WithValue(ctx, ContextKeyTaskID, m.ID) p := NewTaskParam(m.Args, m.Kwargs) return task(ctx, p) }