在工作流内部终止当前工作流时,如何获取 RunID?

huangapple go评论80阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2022年8月4日 11:04:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/73229921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定