Skip to content
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

Add GetUnhandledSignalNames #993

Merged
merged 5 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions internal/internal_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ func executeDispatcher(ctx Context, dispatcher dispatcher, timeout time.Duration
return
}

us := getWorkflowEnvOptions(ctx).getUnhandledSignals()
us := getWorkflowEnvOptions(ctx).getUnhandledSignalNames()
if len(us) > 0 {
env.GetLogger().Info("Workflow has unhandled signals", "SignalNames", us)
}
Expand Down Expand Up @@ -1416,8 +1416,13 @@ func (w *WorkflowOptions) getSignalChannel(ctx Context, signalName string) Recei
return ch
}

// getUnhandledSignals checks if there are any signal channels that have data to be consumed.
func (w *WorkflowOptions) getUnhandledSignals() []string {
// GetUnhandledSignalNames returns signal names that have unconsumed signals.
func GetUnhandledSignalNames(ctx Context) []string {
return getWorkflowEnvOptions(ctx).getUnhandledSignalNames()
}

// getUnhandledSignalNames returns signal names that have unconsumed signals.
func (w *WorkflowOptions) getUnhandledSignalNames() []string {
var unhandledSignals []string
for k, c := range w.signalChannels {
ch := c.(*channelImpl)
Expand Down
4 changes: 2 additions & 2 deletions internal/internal_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,14 @@ func signalWorkflowTest(ctx Context) ([]byte, error) {
s.Select(ctx)

// Check un handled signals.
list := getWorkflowEnvOptions(ctx).getUnhandledSignals()
list := getWorkflowEnvOptions(ctx).getUnhandledSignalNames()
if len(list) != 1 || list[0] != "testSig3" {
panic("expecting one unhandled signal")
}
ch3 := GetSignalChannel(ctx, "testSig3")
ch3.Receive(ctx, &v)
result += v
list = getWorkflowEnvOptions(ctx).getUnhandledSignals()
list = getWorkflowEnvOptions(ctx).getUnhandledSignalNames()
if len(list) != 0 {
panic("expecting no unhandled signals")
}
Expand Down
5 changes: 5 additions & 0 deletions workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ func GetMetricsHandler(ctx Context) metrics.Handler {
return internal.GetMetricsHandler(ctx)
}

// GetUnhandledSignalNames returns signal names that have unconsumed signals.
func GetUnhandledSignalNames(ctx Context) []string {
return internal.GetUnhandledSignalNames(ctx)
}

// RequestCancelExternalWorkflow can be used to request cancellation of an external workflow.
// Input workflowID is the workflow ID of target workflow.
// Input runID indicates the instance of a workflow. Input runID is optional (default is ""). When runID is not specified,
Expand Down