Skip to content

Commit 0cfc77c

Browse files
committed
Fixes metadata to string
Signed-off-by: joshvanl <[email protected]>
1 parent afb05cb commit 0cfc77c

File tree

3 files changed

+38
-76
lines changed

3 files changed

+38
-76
lines changed

workflow/api.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"time"
55

66
"github.com/dapr/durabletask-go/api"
7+
"github.com/dapr/durabletask-go/api/protos"
8+
"github.com/dapr/kit/ptr"
79
"google.golang.org/protobuf/types/known/wrapperspb"
810
)
911

@@ -83,11 +85,11 @@ func WithRecursivePurge(recursive bool) PurgeOptions {
8385
}
8486

8587
func WorkflowMetadataIsRunning(o *WorkflowMetadata) bool {
86-
return api.OrchestrationMetadataIsComplete(o.metadata)
88+
return api.OrchestrationMetadataIsComplete(ptr.Of(protos.OrchestrationMetadata(*o)))
8789
}
8890

8991
func WorkflowMetadataIsComplete(o *WorkflowMetadata) bool {
90-
return api.OrchestrationMetadataIsComplete(o.metadata)
92+
return api.OrchestrationMetadataIsComplete(ptr.Of(protos.OrchestrationMetadata(*o)))
9193
}
9294

9395
func WithRerunInput(input any) RerunOptions {

workflow/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (c *Client) FetchWorkflowMetadata(ctx context.Context, id string, opts ...F
5353
oops[i] = api.FetchOrchestrationMetadataOptions(o)
5454
}
5555
meta, err := c.thgc.FetchOrchestrationMetadata(ctx, api.InstanceID(id), oops...)
56-
return &WorkflowMetadata{metadata: meta}, err
56+
return (*WorkflowMetadata)(meta), err
5757
}
5858

5959
// WaitForWorkflowStart waits for an workflow to start running and returns an
@@ -68,7 +68,7 @@ func (c *Client) WaitForWorkflowStart(ctx context.Context, id string, opts ...Fe
6868
oops[i] = api.FetchOrchestrationMetadataOptions(o)
6969
}
7070
meta, err := c.thgc.WaitForOrchestrationStart(ctx, api.InstanceID(id), oops...)
71-
return &WorkflowMetadata{meta}, err
71+
return (*WorkflowMetadata)(meta), err
7272
}
7373

7474
// WaitForWorkflowCompletion waits for an workflow to complete and returns an
@@ -83,7 +83,7 @@ func (c *Client) WaitForWorkflowCompletion(ctx context.Context, id string, opts
8383
oops[i] = api.FetchOrchestrationMetadataOptions(o)
8484
}
8585
meta, err := c.thgc.WaitForOrchestrationCompletion(ctx, api.InstanceID(id), oops...)
86-
return &WorkflowMetadata{meta}, err
86+
return (*WorkflowMetadata)(meta), err
8787
}
8888

8989
// TerminateWorkflow terminates a running workflow by causing it to stop

workflow/state.go

Lines changed: 31 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,41 @@ package workflow
22

33
import (
44
"github.com/dapr/durabletask-go/api"
5-
"github.com/dapr/durabletask-go/backend"
5+
"github.com/dapr/durabletask-go/api/protos"
66
)
77

8-
type Status int
9-
108
const (
11-
StatusRunning Status = iota
12-
StatusCompleted
13-
StatusContinuedAsNew
14-
StatusFailed
15-
StatusCanceled
16-
StatusTerminated
17-
StatusPending
18-
StatusSuspended
19-
StatusUnknown
9+
StatusRunning = api.RUNTIME_STATUS_RUNNING
10+
StatusCompleted = api.RUNTIME_STATUS_COMPLETED
11+
StatusContinuedAsNew = api.RUNTIME_STATUS_CONTINUED_AS_NEW
12+
StatusFailed = api.RUNTIME_STATUS_FAILED
13+
StatusCanceled = api.RUNTIME_STATUS_CANCELED
14+
StatusTerminated = api.RUNTIME_STATUS_TERMINATED
15+
StatusPending = api.RUNTIME_STATUS_PENDING
16+
StatusSuspended = api.RUNTIME_STATUS_SUSPENDED
2017
)
2118

22-
// String returns the runtime status as a string.
23-
func (s Status) String() string {
24-
status := [...]string{
25-
"RUNNING",
26-
"COMPLETED",
27-
"CONTINUED_AS_NEW",
28-
"FAILED",
29-
"CANCELED",
30-
"TERMINATED",
31-
"PENDING",
32-
"SUSPENDED",
33-
}
34-
if s > StatusSuspended || s < StatusRunning {
35-
return "UNKNOWN"
36-
}
37-
return status[s]
38-
}
39-
40-
func (s Status) RuntimeStatus() api.OrchestrationStatus {
41-
switch s {
42-
case StatusRunning:
43-
return api.RUNTIME_STATUS_RUNNING
44-
case StatusCompleted:
45-
return api.RUNTIME_STATUS_COMPLETED
46-
case StatusContinuedAsNew:
47-
return api.RUNTIME_STATUS_CONTINUED_AS_NEW
48-
case StatusFailed:
49-
return api.RUNTIME_STATUS_FAILED
50-
case StatusCanceled:
51-
return api.RUNTIME_STATUS_CANCELED
52-
case StatusTerminated:
53-
return api.RUNTIME_STATUS_TERMINATED
54-
case StatusPending:
55-
return api.RUNTIME_STATUS_PENDING
56-
case StatusSuspended:
57-
return api.RUNTIME_STATUS_SUSPENDED
58-
}
59-
return -1
60-
}
61-
62-
type WorkflowMetadata struct {
63-
metadata *backend.OrchestrationMetadata
64-
}
65-
66-
// RuntimeStatus returns the status from a workflow state.
67-
func (w *WorkflowMetadata) RuntimeStatus() Status {
68-
s := Status(w.metadata.GetRuntimeStatus().Number())
69-
return s
70-
}
71-
72-
func (w *WorkflowMetadata) Metadata() *backend.OrchestrationMetadata {
73-
return w.metadata
74-
}
75-
76-
func convertStatusSlice(ss []Status) []api.OrchestrationStatus {
77-
out := []api.OrchestrationStatus{}
78-
for _, s := range ss {
79-
out = append(out, s.RuntimeStatus())
19+
type WorkflowMetadata protos.OrchestrationMetadata
20+
21+
func (w WorkflowMetadata) String() string {
22+
switch w.RuntimeStatus {
23+
case api.RUNTIME_STATUS_RUNNING:
24+
return "RUNNING"
25+
case api.RUNTIME_STATUS_COMPLETED:
26+
return "COMPLETED"
27+
case api.RUNTIME_STATUS_CONTINUED_AS_NEW:
28+
return "CONTINUED_AS_NEW"
29+
case api.RUNTIME_STATUS_FAILED:
30+
return "FAILED"
31+
case api.RUNTIME_STATUS_CANCELED:
32+
return "CANCELED"
33+
case api.RUNTIME_STATUS_TERMINATED:
34+
return "TERMINATED"
35+
case api.RUNTIME_STATUS_PENDING:
36+
return "PENDING"
37+
case api.RUNTIME_STATUS_SUSPENDED:
38+
return "SUSPENDED"
39+
default:
40+
return ""
8041
}
81-
return out
8242
}

0 commit comments

Comments
 (0)