我是时态的新手,使用Go SDK。客户端接口定义了一个CheckHealth 方法。我在哪里可以找到一个简单的例子来说明它的用法?我在样本里什么也找不到。
我得到了要执行的方法,但它没有返回任何内容:
package main
import (
"context"
"log"
"go.temporal.io/sdk/client"
"github.com/temporalio/samples-go/helloworld"
)
func main() {
log.Println("Starting")
// The client is a heavyweight object that should be created once per process.
c, err := client.Dial(client.Options{})
if err != nil {
log.Fatalln("Unable to create client", err)
}
log.Println("Client created", c)
// Check client health
checkHealthRequest := client.CheckHealthRequest{
}
checkHealthResponse, err := c.CheckHealth(context.Background(), &checkHealthRequest)
if err != nil {
log.Fatalln("Unable to check health", err)
}
log.Println("checkHealthResponse", checkHealthResponse)
defer c.Close()
workflowOptions := client.StartWorkflowOptions{
ID: "hello_world_workflowID",
TaskQueue: "hello-world",
}
we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, helloworld.Workflow, "Temporal")
if err != nil {
log.Fatalln("Unable to execute workflow", err)
}
log.Println("Started workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID())
// Synchronously wait for the workflow completion.
var result string
err = we.Get(context.Background(), &result)
if err != nil {
log.Fatalln("Unable get workflow result", err)
}
log.Println("Workflow result:", result)
}返回:
gitpod /workspace/samples-go (main) $ go run helloworld/starter/main_matt.go
2022/08/01 03:15:38 Starting
2022/08/01 03:15:38 INFO No logger configured for temporal client. Created default one.
2022/08/01 03:15:38 Client created &{0xc0001a8950 0xc0002a7180 default 0xc0002aa3c0 0xc0001a4c18 {} 15492@temporalio-samplesgo-3fes2zok5o7@ 0xc0001fe460 [] [] 0xc0001a8958 0xc00019fc50 0xc0002b6860 {{0 0} 0 0 0 0}}
2022/08/01 03:15:38 checkHealthResponse &{}
2022/08/01 03:15:38 Started workflow WorkflowID hello_world_workflowID RunID 80727872-4df5-4fab-b96a-484276748e36
2022/08/01 03:15:38 Workflow result: Hello Temporal!发布于 2022-08-01 03:33:54
根据Cerise Limón的评论所作的答复
package main
import (
"context"
"log"
"go.temporal.io/sdk/client"
"github.com/temporalio/samples-go/helloworld"
)
func main() {
log.Println("Starting")
// The client is a heavyweight object that should be created once per process.
c, err := client.Dial(client.Options{})
if err != nil {
log.Fatalln("Unable to create client", err)
}
log.Println("Client created", c)
// Check client health
// The documentation says "If the check fails, an error is returned." The health is good if err == nil.
if _, err := c.CheckHealth(context.Background(), &client.CheckHealthRequest{}); err != nil {
/* health is bad */
log.Println("Health is bad")
} else {
/* health is good */
log.Println("Health is good")
}
defer c.Close()
workflowOptions := client.StartWorkflowOptions{
ID: "hello_world_workflowID",
TaskQueue: "hello-world",
}
we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, helloworld.Workflow, "Temporal")
if err != nil {
log.Fatalln("Unable to execute workflow", err)
}
log.Println("Started workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID())
// Synchronously wait for the workflow completion.
var result string
err = we.Get(context.Background(), &result)
if err != nil {
log.Fatalln("Unable get workflow result", err)
}
log.Println("Workflow result:", result)
}gitpod /workspace/samples-go (main) $ go run helloworld/starter/main_matt.go
2022/08/01 03:30:29 Starting
2022/08/01 03:30:29 INFO No logger configured for temporal client. Created default one.
2022/08/01 03:30:29 Client created &{0xc00012e950 0xc000231180 default 0xc0002323c0 0xc00012ac18 {} 18770@temporalio-samplesgo-3fes2zok5o7@ 0xc00017e460 [] [] 0xc00012e958 0xc000125c50 0xc000038748 {{0 0} 0 0 0 0}}
2022/08/01 03:30:29 Health is good
2022/08/01 03:30:29 Started workflow WorkflowID hello_world_workflowID RunID 03cfd328-77c1-4d7a-9d5e-86d82e44c034
2022/08/01 03:30:29 Workflow result: Hello Temporal!https://stackoverflow.com/questions/73188412
复制相似问题