英文:
Temporal, How to get RunID while being inside a workflow to terminate the current workflow?
问题
我正在尝试测试一个 Temporal(时间)函数,以下是我迄今为止尝试过的代码:
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
}
}
在工作流中,我想要一个条件,可以终止当前的工作流。但是我不知道如何在工作流中获取 WORKFLOW_ID 和 RUN_ID。
英文:
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
答案1
得分: 2
没有用于终止自身的工作流 API。要停止当前的工作流,请返回(可以是一个值或一个错误)。
英文:
There is no Workflow API for terminating itself. To stop the current Workflow, return. (Either a value or an error.)
答案2
得分: 2
你可以通过以下方式获取当前执行的运行 ID:
workflow.GetInfo(ctx).WorkflowExecution.RunID
工作流 ID:
workflow.GetInfo(ctx).WorkflowExecution.ID
要终止工作流,你可以调用活动(传入这些信息),该活动可以使用客户端 API 终止工作流。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论