forked from temporalio/temporalite-archived
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from grantfuhr/new-worker-with-options
New worker with options
- Loading branch information
Showing
4 changed files
with
176 additions
and
0 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