Skip to content

Commit 34fd5ad

Browse files
committed
Resolve todo and add tracing
1 parent 2cebf16 commit 34fd5ad

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

backend/redis/scripts/complete_workflow_task.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ if state == ContinuedAsNew or state == Finished then
165165

166166
instance["completed_at"] = now
167167

168-
-- TODO: Set auto expiration
169-
170168
redis.call("SREM", activeInstancesKey, instanceSegment)
171169
end
172170

backend/redis/workflow.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import (
1010
"github.com/cschleiden/go-workflows/backend"
1111
"github.com/cschleiden/go-workflows/backend/history"
1212
"github.com/cschleiden/go-workflows/core"
13+
"github.com/cschleiden/go-workflows/internal/log"
14+
"github.com/cschleiden/go-workflows/internal/tracing"
1315
"github.com/cschleiden/go-workflows/internal/workflowerrors"
1416
"github.com/redis/go-redis/v9"
17+
"go.opentelemetry.io/otel/attribute"
18+
"go.opentelemetry.io/otel/trace"
1519
)
1620

1721
func (rb *redisBackend) GetWorkflowTask(ctx context.Context) (*backend.WorkflowTask, error) {
@@ -245,27 +249,26 @@ func (rb *redisBackend) CompleteWorkflowTask(
245249
// If there are pending events, queue the instance again
246250
// No args/keys needed
247251

248-
// Commit transaction
252+
// Run script
249253
_, err := completeWorkflowTaskCmd.Run(ctx, rb.rdb, keys, args...).Result()
250254
if err != nil {
251255
return fmt.Errorf("completing workflow task: %w", err)
252256
}
253257

254258
if state == core.WorkflowInstanceStateFinished || state == core.WorkflowInstanceStateContinuedAsNew {
255259
// Trace workflow completion
256-
// TODO: Return metadata from script
257-
// ctx, err = (&tracing.TracingContextPropagator{}).Extract(ctx, instanceState.Metadata)
258-
// if err != nil {
259-
// rb.Logger().Error("extracting tracing context", log.ErrorKey, err)
260-
// }
261-
262-
// _, span := rb.Tracer().Start(ctx, "WorkflowComplete",
263-
// trace.WithAttributes(
264-
// attribute.String(log.NamespaceKey+log.InstanceIDKey, instanceState.Instance.InstanceID),
265-
// ))
266-
// span.End()
267-
268-
// TODO: Move to script
260+
ctx, err = (&tracing.TracingContextPropagator{}).Extract(ctx, task.Metadata)
261+
if err != nil {
262+
rb.Logger().Error("extracting tracing context", log.ErrorKey, err)
263+
}
264+
265+
_, span := rb.Tracer().Start(ctx, "WorkflowComplete",
266+
trace.WithAttributes(
267+
attribute.String(log.NamespaceKey+log.InstanceIDKey, task.WorkflowInstance.InstanceID),
268+
))
269+
span.End()
270+
271+
// Auto expiration
269272
if rb.options.AutoExpiration > 0 {
270273
if err := setWorkflowInstanceExpiration(ctx, rb.rdb, instance, rb.options.AutoExpiration); err != nil {
271274
return fmt.Errorf("setting workflow instance expiration: %w", err)

0 commit comments

Comments
 (0)