Skip to content

Commit 3cebc4b

Browse files
Add Go snippets for Workflows
1 parent d3713b7 commit 3cebc4b

33 files changed

+1492
-99
lines changed

.vale.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ StylesPath = "vale/styles"
22

33
Vocab = docs
44
Packages = Google
5-
IgnoredScopes = code, tt, img, url, a
5+
IgnoredScopes = code, tt, img, url, a, text.frontmatter
66
SkippedScopes = script, style, pre, figure, code
77
MinAlertLevel = warning
88

api-reference/go/datasets/Collections.Create.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func (collectionClient) Create(
99
ctx context.Context,
1010
datasetID uuid.UUID,
1111
collectionName string,
12-
) (*Collection, error)
12+
) (*datasets.Collection, error)
1313
```
1414

1515
Create a collection in the dataset.

api-reference/go/datasets/Collections.Get.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func (collectionClient) Get(
99
ctx context.Context,
1010
datasetID uuid.UUID,
1111
name string,
12-
) (*Collection, error)
12+
) (*datasets.Collection, error)
1313
```
1414

1515
Get a dataset by its slug.

api-reference/go/datasets/Collections.List.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ icon: layer-group
88
func (collectionClient) List(
99
ctx context.Context,
1010
datasetID uuid.UUID,
11-
) ([]*Collection, error)
11+
) ([]*datasets.Collection, error)
1212
```
1313

1414
List the available collections in a dataset.

api-reference/go/datasets/Datapoints.Delete.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func (datapointClient) Delete(
99
ctx context.Context,
1010
collectionID uuid.UUID,
1111
datapoints any,
12-
) (*DeleteResponse, error)
12+
) (*datasets.DeleteResponse, error)
1313
```
1414

1515
Delete data points from a collection.

api-reference/go/datasets/Datapoints.DeleteIDs.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func (datapointClient) DeleteIDs(
99
ctx context.Context,
1010
collectionID uuid.UUID,
1111
datapointIDs []uuid.UUID,
12-
) (*DeleteResponse, error)
12+
) (*datasets.DeleteResponse, error)
1313
```
1414

1515
Delete data points from a collection.

api-reference/go/datasets/Datapoints.Ingest.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func (datapointClient) Ingest(
1010
collectionID uuid.UUID,
1111
datapoints any,
1212
allowExisting bool,
13-
) (*IngestResponse, error)
13+
) (*datasets.IngestResponse, error)
1414
```
1515

1616
Ingest data points into a collection.

api-reference/go/datasets/Datapoints.Load.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func (datapointClient) Load(
99
ctx context.Context,
1010
collectionID uuid.UUID,
1111
interval interval.LoadInterval,
12-
options ...LoadOption,
12+
options ...datasets.LoadOption,
1313
) iter.Seq2[[]byte, error]
1414
```
1515

@@ -26,7 +26,7 @@ The output sequence can be transformed into a typed `proto.Message` using `Colle
2626
<ParamField path="interval" type="interval.LoadInterval">
2727
The interval for which to load data points
2828
</ParamField>
29-
<ParamField path="options" type="[]LoadOption">
29+
<ParamField path="options" type="[]datasets.LoadOption">
3030
Options for loading data points
3131
</ParamField>
3232

api-reference/go/datasets/Datapoints.LoadInto.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func (datapointClient) LoadInto(
1010
collectionID uuid.UUID,
1111
interval interval.LoadInterval,
1212
datapoints any,
13-
options ...LoadOption,
13+
options ...datasets.LoadOption,
1414
) error
1515
```
1616

@@ -27,7 +27,7 @@ Load a range of data points in this collection in a specified interval.
2727
<ParamField path="datapoints" type="[]proto.Message">
2828
The datapoints to load into
2929
</ParamField>
30-
<ParamField path="options" type="[]LoadOption">
30+
<ParamField path="options" type="[]datasets.LoadOption">
3131
Options for loading data points
3232
</ParamField>
3333

api-reference/go/datasets/Get.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ icon: laptop-code
88
func (datasetClient) Get(
99
ctx context.Context,
1010
slug string,
11-
) (*Dataset, error)
11+
) (*datasets.Dataset, error)
1212
```
1313

1414
Get a dataset by its slug.

api-reference/go/datasets/List.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ icon: laptop-code
55
---
66

77
```go
8-
func (datasetClient) List(ctx context.Context) ([]*Dataset, error)
8+
func (datasetClient) List(ctx context.Context) ([]*datasets.Dataset, error)
99
```
1010

1111
Fetch all available datasets.

api-reference/go/workflows/Clusters.Create.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ icon: circle-nodes
88
func (*ClusterClient) Create(
99
ctx context.Context,
1010
name string,
11-
) (*Cluster, error)
11+
) (*workflows.Cluster, error)
1212
```
1313

1414
Create a cluster.

api-reference/go/workflows/Clusters.Get.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ icon: circle-nodes
88
func (*ClusterClient) Get(
99
ctx context.Context,
1010
slug string,
11-
) (*Cluster, error)
11+
) (*workflows.Cluster, error)
1212
```
1313

1414
Get a cluster by its slug.

api-reference/go/workflows/Clusters.List.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ icon: circle-nodes
55
---
66

77
```go
8-
func (*ClusterClient) List(ctx context.Context) ([]*Cluster, error)
8+
func (*ClusterClient) List(ctx context.Context) ([]*workflows.Cluster, error)
99
```
1010

1111
Fetch all available clusters.

api-reference/go/workflows/Jobs.Get.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ icon: diagram-project
88
func (*JobClient) Get(
99
ctx context.Context,
1010
jobID uuid.UUID,
11-
) (*Job, error)
11+
) (*workflows.Job, error)
1212
```
1313

1414
Get a job by its id.

api-reference/go/workflows/Jobs.List.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ icon: diagram-project
88
func (*JobClient) List(
99
ctx context.Context,
1010
interval interval.LoadInterval,
11-
) iter.Seq2[*Job, error]
11+
) iter.Seq2[*workflows.Job, error]
1212
```
1313

1414
List all available jobs.

api-reference/go/workflows/Jobs.Submit.mdx

+17-12
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ icon: diagram-project
88
func (*JobClient) Submit(
99
ctx context.Context,
1010
jobName string,
11-
clusterSlug string,
12-
maxRetries int,
13-
tasks ...Task,
14-
) (*Job, error)
11+
cluster *workflows.Cluster,
12+
tasks []workflows.Task,
13+
options ...job.SubmitOption
14+
) (*workflows.Job, error)
1515
```
1616

1717
Submit a job.
@@ -21,15 +21,21 @@ Submit a job.
2121
<ParamField path="jobName" type="string">
2222
The name of the job
2323
</ParamField>
24-
<ParamField path="clusterSlug" type="string">
25-
The [cluster slug](/workflows/concepts/clusters#managing-clusters) for the cluster to run the root task on
26-
</ParamField>
27-
<ParamField path="maxRetries" type="int">
28-
The maximum number of [retries](/workflows/concepts/tasks#retry-handling) for the subtask in case it fails
24+
<ParamField path="cluster" type="*Cluster">
25+
The [cluster](/workflows/concepts/clusters#managing-clusters) to run the root task on
2926
</ParamField>
3027
<ParamField path="tasks" type="[]Task">
3128
The root task for the job. This task is executed first and can submit subtasks to manage the entire workflow. A job can have optionally consist of multiple root tasks.
3229
</ParamField>
30+
<ParamField path="options" type="[]job.SubmitOption">
31+
Options for the job
32+
</ParamField>
33+
34+
## Options
35+
36+
<ParamField path="WithMaxRetries(maxRetries int64)" default="0">
37+
Set the maximum number of [retries](/workflows/concepts/tasks#retry-handling) for the subtask in case it fails
38+
</ParamField>
3339

3440
## Returns
3541

@@ -39,9 +45,8 @@ A job object.
3945
```go Go
4046
job, err := client.Jobs.Submit(ctx,
4147
"My job",
42-
"my-cluster-tZD9Ca1qsqt3V",
43-
3,
44-
rootTask,
48+
cluster,
49+
[]workflows.Task{rootTask},
4550
)
4651
```
4752
</RequestExample>

api-reference/go/workflows/NewTaskRunner.mdx

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ icon: gear-code
55
---
66

77
```go
8-
func (*Client) NewTaskRunner(options ...TaskRunnerOption) (*TaskRunner, error)
8+
func (*Client) NewTaskRunner(
9+
cluster *workflows.Cluster,
10+
options ...runner.Option,
11+
) (*workflows.TaskRunner, error)
912
```
1013

1114
Initialize a task runner.
1215

1316
## Parameters
1417

15-
<ParamField path="options" type="[]TaskRunnerOption">
18+
<ParamField path="cluster" type="*Cluster">
19+
The [cluster](/workflows/concepts/clusters#managing-clusters) to connect to
20+
</ParamField>
21+
<ParamField path="options" type="[]runner.Option">
1622
Options for initializing the task runner
1723
</ParamField>
1824

1925
## Options
2026

21-
<ParamField path="WithCluster(clusterSlug string)" default="">
22-
Set the cluster slug to use for the task runner
23-
</ParamField>
2427
<ParamField path="WithRunnerLogger(logger *slog.Logger)" default="slog.Default()">
2528
Set the logger to use for the task runner
2629
</ParamField>
@@ -34,8 +37,6 @@ The created task runner object.
3437

3538
<RequestExample>
3639
```go Go
37-
runner, err := client.NewTaskRunner(
38-
workflows.WithCluster("my-cluster-tZD9Ca1qsqt3V"),
39-
)
40+
runner, err := client.NewTaskRunner()
4041
```
4142
</RequestExample>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: workflows.SubmitSubtask
3+
sidebarTitle: SubmitSubtask
4+
icon: code
5+
---
6+
7+
```go
8+
workflows.SubmitSubtask(
9+
ctx context.Context,
10+
task workflows.Task,
11+
options ...subtask.SubmitOption,
12+
) (subtask.FutureTask, error)
13+
```
14+
15+
Submit a subtask to the task runner.
16+
17+
This function is intended to be used in tasks.
18+
19+
## Parameters
20+
21+
<ParamField path="task" type="Task">
22+
A subtask to submit
23+
</ParamField>
24+
<ParamField path="options" type="[]subtask.SubmitOption">
25+
Options for the subtask
26+
</ParamField>
27+
28+
## Options
29+
30+
<ParamField path="WithDependencies(dependencies ...FutureTask)">
31+
Set dependencies for the task
32+
</ParamField>
33+
<ParamField path="WithClusterSlug(clusterSlug string)" default="cluster of the task runner">
34+
Set the cluster slug of the cluster where the task will be executed.
35+
</ParamField>
36+
<ParamField path="WithMaxRetries(maxRetries int64)" default="0">
37+
Set the maximum number of [retries](/workflows/concepts/tasks#retry-handling) for the subtask in case it fails
38+
</ParamField>
39+
40+
## Returns
41+
42+
A future task that can be used to set dependencies between tasks.
43+
44+
<RequestExample>
45+
```go Go
46+
47+
type MySubTask struct {
48+
Sensor string
49+
Value float64
50+
}
51+
52+
type Task struct{}
53+
54+
func (t *Task) Execute(ctx context.Context) error {
55+
err := workflows.SubmitSubtask(ctx,
56+
&MySubTask{
57+
Sensor: "A",
58+
Value: 42,
59+
},
60+
)
61+
if err != nil {
62+
return fmt.Errorf("failed to submit subtasks: %w", err)
63+
}
64+
65+
return nil
66+
}
67+
```
68+
</RequestExample>

api-reference/go/workflows/SubmitSubtasks.mdx

+34-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ icon: code
55
---
66

77
```go
8-
workflows.SubmitSubtasks(ctx context.Context, tasks ...Task) error
8+
workflows.SubmitSubtasks(
9+
ctx context.Context,
10+
tasks []workflows.Task,
11+
options ...subtask.SubmitOption,
12+
) ([]subtask.FutureTask, error)
913
```
1014

11-
Submit multiple subtasks to the task runner.
15+
Submit multiple subtasks to the task runner. Same as [SubmitSubtask](/api-reference/go/workflows/SubmitSubtask), but accepts a list of tasks.
1216

1317
This function is intended to be used in tasks.
1418

@@ -17,10 +21,25 @@ This function is intended to be used in tasks.
1721
<ParamField path="tasks" type="[]Task">
1822
A list of tasks to submit
1923
</ParamField>
24+
<ParamField path="options" type="[]subtask.SubmitOption">
25+
Options for the subtasks
26+
</ParamField>
27+
28+
## Options
29+
30+
<ParamField path="WithDependencies(dependencies ...FutureTask)">
31+
Set dependencies for the tasks
32+
</ParamField>
33+
<ParamField path="WithClusterSlug(clusterSlug string)" default="cluster of the task runner">
34+
Set the cluster slug of the cluster where the tasks will be executed.
35+
</ParamField>
36+
<ParamField path="WithMaxRetries(maxRetries int64)" default="0">
37+
Set the maximum number of [retries](/workflows/concepts/tasks#retry-handling) for the subtasks in case it fails
38+
</ParamField>
2039

2140
## Returns
2241

23-
An error if the tasks could not be submitted.
42+
A list of future tasks that can be used to set dependencies between tasks.
2443

2544
<RequestExample>
2645
```go Go
@@ -33,10 +52,18 @@ type MySubTask struct {
3352
type Task struct{}
3453

3554
func (t *Task) Execute(ctx context.Context) error {
36-
err := workflows.SubmitSubtasks(ctx, &MySubTask{
37-
Sensor: "A",
38-
Value: 42,
39-
})
55+
err := workflows.SubmitSubtasks(ctx,
56+
[]workflows.Task{
57+
&MySubTask{
58+
Sensor: "A",
59+
Value: 42,
60+
},
61+
&MySubTask{
62+
Sensor: "B",
63+
Value: 42,
64+
}
65+
},
66+
)
4067
if err != nil {
4168
return fmt.Errorf("failed to submit subtasks: %w", err)
4269
}

0 commit comments

Comments
 (0)