This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods to create new test workers with custom options (#81)
- Loading branch information
Showing
5 changed files
with
209 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package helloworld | ||
|
||
import ( | ||
"time" | ||
|
||
"go.temporal.io/sdk/interceptor" | ||
"go.temporal.io/sdk/workflow" | ||
) | ||
|
||
var _ interceptor.Interceptor = &Interceptor{} | ||
|
||
type Interceptor struct { | ||
interceptor.InterceptorBase | ||
} | ||
|
||
type WorkflowInterceptor struct { | ||
interceptor.WorkflowInboundInterceptorBase | ||
} | ||
|
||
func NewTestInterceptor() *Interceptor { | ||
return &Interceptor{} | ||
} | ||
|
||
func (i *Interceptor) InterceptClient(next interceptor.ClientOutboundInterceptor) interceptor.ClientOutboundInterceptor { | ||
return i.InterceptorBase.InterceptClient(next) | ||
} | ||
|
||
func (i *Interceptor) InterceptWorkflow(ctx workflow.Context, next interceptor.WorkflowInboundInterceptor) interceptor.WorkflowInboundInterceptor { | ||
return &WorkflowInterceptor{ | ||
WorkflowInboundInterceptorBase: interceptor.WorkflowInboundInterceptorBase{ | ||
Next: next, | ||
}, | ||
} | ||
} | ||
|
||
func (i *WorkflowInterceptor) Init(outbound interceptor.WorkflowOutboundInterceptor) error { | ||
return i.Next.Init(outbound) | ||
} | ||
|
||
func (i *WorkflowInterceptor) ExecuteWorkflow(ctx workflow.Context, in *interceptor.ExecuteWorkflowInput) (interface{}, error) { | ||
version := workflow.GetVersion(ctx, "version", workflow.DefaultVersion, 1) | ||
var err error | ||
|
||
if version != workflow.DefaultVersion { | ||
var vpt string | ||
err = workflow.ExecuteLocalActivity( | ||
workflow.WithLocalActivityOptions(ctx, workflow.LocalActivityOptions{ScheduleToCloseTimeout: time.Second}), | ||
"TestIntercept", | ||
).Get(ctx, &vpt) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return i.Next.ExecuteWorkflow(ctx, in) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters