I am trying to test a temporal, here is what I have tried so far
func (h *Temporal) Notification(ctx workflow.Context, activityType string, sleep time.Duration) (TemporalResult, error) { //Response must have error
ao := workflow.ActivityOptions{
StartToCloseTimeout: time.Hour * 1000,
HeartbeatTimeout: time.Hour * 1000,
}
ctx = workflow.WithActivityOptions(ctx, ao)
if 1=1 {
c.TerminateWorkflow(context.Background(), WORKFLOW_ID, RUN_ID )
} else {
workflow.Sleep(ctx, sleep)
var result workflow.Future
result = workflow.ExecuteActivity(ctx, h.SimpleActivity)
return yourActivityResult, nil
}
In side the workflow, I want to have a condition where it could terminate the current workflow. But I do not know how to get WORKFLOW_ID and RUN_ID inside a workflow
CodePudding user response:
There is no Workflow API for terminating itself. To stop the current Workflow, return. (Either a value or an error.)
CodePudding user response:
You can get the current executions run id via:
workflow.GetInfo(ctx).WorkflowExecution.RunID
Workflow id:
workflow.GetInfo(ctx).WorkflowExecution.ID
To terminate you could invoke activity (pass in this info) which can use client api to terminate the workflow.