Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go-sandbox/activities/standalone/activity.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @@@SNIPSTART go-standalone-activity-quickstart-activity
package standalone

import (
Expand All @@ -13,3 +14,4 @@ const (
func Activity(ctx context.Context, name string) (string, error) {
return fmt.Sprintf("Hello %s!", name), nil
}
// @@@SNIPEND
39 changes: 35 additions & 4 deletions go-sandbox/activities/standalone/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import (
"time"

"go.temporal.io/sdk/client"
"go.temporal.io/sdk/contrib/envconfig"

"my-org/quickstart/activities/standalone"
)

func main() {
command := flag.String("command", "start", "one of: start, handle, list, count")
command := flag.String("command", "start", "one of: start, start-by-name, handle, list, count")
runID := flag.String("run-id", "", "Run ID of the Activity Execution for the handle command")
flag.Parse()

c, err := client.Dial(client.Options{})
c, err := client.Dial(envconfig.MustLoadDefaultClientOptions())
if err != nil {
log.Fatalln("Unable to create client", err)
}
Expand All @@ -25,6 +26,8 @@ func main() {
switch *command {
case "start":
startActivity(c)
case "start-by-name":
startActivityByName(c)
case "handle":
getActivityHandle(c, *runID)
case "list":
Expand All @@ -37,14 +40,19 @@ func main() {
}

func startActivity(c client.Client) {
handle, err := c.ExecuteActivity(context.Background(), client.StartActivityOptions{
// @@@SNIPSTART go-standalone-activity-quickstart-execute
options := client.StartActivityOptions{
ID: standalone.ActivityID,
TaskQueue: standalone.TaskQueue,
StartToCloseTimeout: 10 * time.Second,
}, standalone.Activity, "Temporal")
}

handle, err := c.ExecuteActivity(context.Background(), options, standalone.Activity, "Temporal")
if err != nil {
log.Fatalln("Unable to execute activity", err)
}
log.Println("Started Standalone Activity", "ActivityID", handle.GetID(), "RunID", handle.GetRunID())
// @@@SNIPEND

// @@@SNIPSTART go-standalone-activity-get-result
var result string
Expand All @@ -56,6 +64,29 @@ func startActivity(c client.Client) {
// @@@SNIPEND
}

// startActivityByName starts the same Activity by its registered type name instead of
// a function reference. Use this when the caller can't import the Activity function.
func startActivityByName(c client.Client) {
options := client.StartActivityOptions{
ID: standalone.ActivityID,
TaskQueue: standalone.TaskQueue,
StartToCloseTimeout: 10 * time.Second,
}

// @@@SNIPSTART go-standalone-activity-quickstart-execute-by-name
handle, err := c.ExecuteActivity(context.Background(), options, "Activity", "Temporal")
// @@@SNIPEND
if err != nil {
log.Fatalln("Unable to execute activity", err)
}

var result string
if err := handle.Get(context.Background(), &result); err != nil {
log.Fatalln("Activity failed", err)
}
log.Println("Activity result:", result)
}

func getActivityHandle(c client.Client, runID string) {
// @@@SNIPSTART go-standalone-activity-get-handle
handle := c.GetActivityHandle(client.GetActivityHandleOptions{
Expand Down
5 changes: 4 additions & 1 deletion go-sandbox/activities/standalone/worker/main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// @@@SNIPSTART go-standalone-activity-quickstart-worker
package main

import (
"log"

"go.temporal.io/sdk/client"
"go.temporal.io/sdk/contrib/envconfig"
"go.temporal.io/sdk/worker"

"my-org/quickstart/activities/standalone"
)

func main() {
c, err := client.Dial(client.Options{})
c, err := client.Dial(envconfig.MustLoadDefaultClientOptions())
if err != nil {
log.Fatalln("Unable to create client", err)
}
Expand All @@ -24,3 +26,4 @@ func main() {
log.Fatalln("Unable to start Worker", err)
}
}
// @@@SNIPEND
Loading