-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e735bec
commit b42bf46
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
This sample demonstrates how to setup a workflow to start after a delay. | ||
|
||
### Steps to run this sample: | ||
1) Run a [Temporal service](https://github.com/temporalio/samples-go/tree/main/#how-to-use). | ||
2) Run the following command to start the worker | ||
``` | ||
go run start-delay/worker/main.go | ||
``` | ||
3) Run the following command to start the example | ||
``` | ||
go run start-delay/starter/main.go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"time" | ||
|
||
"github.com/pborman/uuid" | ||
"github.com/temporalio/samples-go/helloworld" | ||
"go.temporal.io/sdk/client" | ||
) | ||
|
||
func main() { | ||
// The client is a heavyweight object that should be created once per process. | ||
c, err := client.Dial(client.Options{ | ||
HostPort: client.DefaultHostPort, | ||
}) | ||
if err != nil { | ||
log.Fatalln("Unable to create client", err) | ||
} | ||
defer c.Close() | ||
|
||
workflowOptions := client.StartWorkflowOptions{ | ||
ID: "startdelay_" + uuid.New(), | ||
TaskQueue: "startdelay", | ||
// The first workflow task will be dispatched in 5 minutes | ||
StartDelay: 5 * time.Minute, | ||
} | ||
|
||
we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, helloworld.Workflow, "from a delayed workflow") | ||
if err != nil { | ||
log.Fatalln("Unable to execute workflow", err) | ||
} | ||
// ExecuteWorkflow will return immediately, but the workflow won't start executing till the StartDelay expires. | ||
log.Println("Scheduled workflow", "WorkflowID", we.GetID(), "RunID", we.GetRunID()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"go.temporal.io/sdk/client" | ||
"go.temporal.io/sdk/worker" | ||
|
||
"github.com/temporalio/samples-go/helloworld" | ||
) | ||
|
||
func main() { | ||
// The client and worker are heavyweight objects that should be created once per process. | ||
c, err := client.Dial(client.Options{ | ||
HostPort: client.DefaultHostPort, | ||
}) | ||
if err != nil { | ||
log.Fatalln("Unable to create client", err) | ||
} | ||
defer c.Close() | ||
|
||
w := worker.New(c, "startdelay", worker.Options{}) | ||
|
||
w.RegisterWorkflow(helloworld.Workflow) | ||
w.RegisterActivity(helloworld.Activity) | ||
|
||
err = w.Run(worker.InterruptCh()) | ||
if err != nil { | ||
log.Fatalln("Unable to start worker", err) | ||
} | ||
} |