Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 1f054c2

Browse files
add python, go, and nodejs
1 parent 8a24e44 commit 1f054c2

File tree

12 files changed

+614
-23
lines changed

12 files changed

+614
-23
lines changed

src/nav.config.ts

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,23 @@ const fullNav: FullNav = {
11861186
},
11871187
],
11881188
},
1189+
{
1190+
title: 'Batch Jobs',
1191+
links: [
1192+
{
1193+
title: 'job()',
1194+
href: '/reference/nodejs/batch/job',
1195+
},
1196+
{
1197+
title: 'job.handler()',
1198+
href: '/reference/nodejs/batch/job-handler',
1199+
},
1200+
{
1201+
title: 'job.send()',
1202+
href: '/reference/nodejs/batch/job-submit',
1203+
},
1204+
],
1205+
},
11891206
{
11901207
title: 'HTTP',
11911208
links: [
@@ -1652,6 +1669,23 @@ const fullNav: FullNav = {
16521669
},
16531670
],
16541671
},
1672+
{
1673+
title: 'Batch Jobs',
1674+
links: [
1675+
{
1676+
title: 'job()',
1677+
href: '/reference/python/batch/job',
1678+
},
1679+
{
1680+
title: 'job.handler()',
1681+
href: '/reference/python/batch/job-handler',
1682+
},
1683+
{
1684+
title: 'job.send()',
1685+
href: '/reference/python/batch/job-submit',
1686+
},
1687+
],
1688+
},
16551689
{
16561690
title: 'Key Value Stores',
16571691
links: [
@@ -1883,6 +1917,23 @@ const fullNav: FullNav = {
18831917
},
18841918
],
18851919
},
1920+
{
1921+
title: 'Batch Jobs',
1922+
links: [
1923+
{
1924+
title: 'job()',
1925+
href: '/reference/dart/batch/job',
1926+
},
1927+
{
1928+
title: 'job.handler()',
1929+
href: '/reference/dart/batch/job-handler',
1930+
},
1931+
{
1932+
title: 'job.send()',
1933+
href: '/reference/dart/batch/job-submit',
1934+
},
1935+
],
1936+
},
18861937
{
18871938
title: 'Key Value Stores',
18881939
links: [
@@ -2063,23 +2114,6 @@ const fullNav: FullNav = {
20632114
},
20642115
],
20652116
},
2066-
{
2067-
title: 'Batch Jobs',
2068-
links: [
2069-
{
2070-
title: 'job()',
2071-
href: '/reference/dart/batch/job',
2072-
},
2073-
{
2074-
title: 'job.handler()',
2075-
href: '/reference/dart/batch/job-handler',
2076-
},
2077-
{
2078-
title: 'job.send()',
2079-
href: '/reference/dart/batch/job-submit',
2080-
},
2081-
],
2082-
},
20832117
],
20842118
['reference/csharp']: [
20852119
{
@@ -2531,6 +2565,10 @@ const fullNav: FullNav = {
25312565
title: 'NewApi()',
25322566
href: '/reference/go/api/api',
25332567
},
2568+
{
2569+
title: 'NewJob()',
2570+
href: '/reference/go/batch/job',
2571+
},
25342572
{
25352573
title: 'NewKv()',
25362574
href: '/reference/go/keyvalue/keyvalue',
@@ -2614,6 +2652,19 @@ const fullNav: FullNav = {
26142652
},
26152653
],
26162654
},
2655+
{
2656+
title: 'Batch Jobs',
2657+
links: [
2658+
{
2659+
title: 'Job.Handler()',
2660+
href: '/reference/go/batch/job-handler',
2661+
},
2662+
{
2663+
title: 'Job.Send()',
2664+
href: '/reference/go/batch/job-submit',
2665+
},
2666+
],
2667+
},
26172668
{
26182669
title: 'Key Value Stores',
26192670
links: [

src/pages/reference/dart/batch/job-handler.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ batch-services:
3232
The middleware service to use as the handler for Job requests.
3333
</Property>
3434
<Property name="opts" type="JobResourceRequirements" nested>
35-
<Property name="cpus">
35+
<Property name="cpus" type="int">
3636
The number of CPUs to allocate to the handler
3737
</Property>
38-
<Property name="gpus">
38+
<Property name="gpus" type="int">
3939
The number of GPUs to allocate to the handler
4040
</Property>
41-
<Property name="memory">
41+
<Property name="memory" type="int">
4242
The amount of memory (MB) to allocate to the handler
4343
</Property>
4444
</Property>
@@ -55,7 +55,7 @@ final analyse = Nitric.job("analyse").allow([JobPermission.submit]);
5555

5656
analyse.handler((ctx) async {
5757
return ctx;
58-
}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0));
58+
});
5959
```
6060

6161
### Create a job handler with custom resource requirements
@@ -67,5 +67,5 @@ final analyse = Nitric.job("analyse").allow([JobPermission.submit]);
6767
6868
analyse.handler((ctx) async {
6969
return ctx;
70-
}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0));
70+
}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 1));
7171
```

src/pages/reference/dart/batch/job-submit.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const description =
22
"Reference for Nitric's Dart library - Submit a batch job request with the Nitric Dart SDK"
33

4-
# Dart - job.submit()()
4+
# Dart - job.submit()
55

66
Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function.
77

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
export const description =
2+
"Reference for Nitric's Go library - Register a job handler to with the Nitric Go SDK"
3+
4+
# Go - job.handler()
5+
6+
Job handlers are the code that is run when a job request is submitted. These handlers should be written in a separate file to your services.
7+
8+
```go
9+
import (
10+
"fmt"
11+
12+
"github.com/nitrictech/go-sdk/nitric"
13+
"github.com/nitrictech/go-sdk/nitric/batch"
14+
)
15+
16+
func main() {
17+
analyse := nitric.NewJob("analyse")
18+
19+
analyse.Handler(nitric.JobResourceRequirements{
20+
Cpus: 1,
21+
Memory: 2048,
22+
Gpus: 0,
23+
}, func(ctx *batch.Ctx) {
24+
// do long running work
25+
})
26+
27+
if err := nitric.Run(); err != nil {
28+
fmt.Println(err)
29+
}
30+
}
31+
```
32+
33+
## Defining Batches
34+
35+
Batches are defined in different files to services and referenced in a project's `nitric.yaml` file. For example:
36+
37+
```yaml
38+
batch-services:
39+
- match: ./batches/*.go
40+
start: go run $SERVICE_PATH
41+
```
42+
43+
## Parameters
44+
45+
<Properties>
46+
<Property name="handler" required type="JobHandler">
47+
The middleware service to use as the handler for Job requests.
48+
</Property>
49+
<Property name="opts" type="JobResourceRequirements" nested>
50+
<Property name="cpus" type="float32">
51+
The number of CPUs to allocate to the handler
52+
</Property>
53+
<Property name="gpus" type="int64">
54+
The number of GPUs to allocate to the handler
55+
</Property>
56+
<Property name="memory" type="int64">
57+
The amount of memory (MB) to allocate to the handler
58+
</Property>
59+
</Property>
60+
</Properties>
61+
62+
## Examples
63+
64+
### Define a job handler
65+
66+
```go
67+
import (
68+
"fmt"
69+
70+
"github.com/nitrictech/go-sdk/nitric"
71+
"github.com/nitrictech/go-sdk/nitric/batch"
72+
)
73+
74+
func main() {
75+
analyse := nitric.NewJob("analyse")
76+
77+
analyse.Handler(nitric.JobResourceRequirements{}, func(ctx *batch.Ctx) {
78+
// do long running work
79+
})
80+
81+
if err := nitric.Run(); err != nil {
82+
fmt.Println(err)
83+
}
84+
}
85+
```
86+
87+
### Create a job handler with custom resource requirements
88+
89+
```go
90+
import (
91+
"fmt"
92+
93+
"github.com/nitrictech/go-sdk/nitric"
94+
"github.com/nitrictech/go-sdk/nitric/batch"
95+
)
96+
97+
func main() {
98+
analyse := nitric.NewJob("analyse")
99+
100+
analyse.Handler(nitric.JobResourceRequirements{
101+
Cpus: 1,
102+
Memory: 2048,
103+
Gpus: 0,
104+
}, func(ctx *batch.Ctx) {
105+
// do long running work
106+
})
107+
108+
if err := nitric.Run(); err != nil {
109+
fmt.Println(err)
110+
}
111+
}
112+
```
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
export const description =
2+
"Reference for Nitric's Go library - Submit a batch job request with the Nitric Go SDK"
3+
4+
# Go - job.submit()
5+
6+
Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function.
7+
8+
```go
9+
import (
10+
"context"
11+
"fmt"
12+
13+
"github.com/nitrictech/go-sdk/nitric"
14+
)
15+
16+
func main() {
17+
analyse, err := nitric.NewJob("analyse").Allow(nitric.JobSubmit)
18+
if err != nil {
19+
fmt.Println(err)
20+
}
21+
22+
analyse.Submit(context.TODO(), map[string]interface{}{
23+
"message": "message contents",
24+
})
25+
26+
if err := nitric.Run(); err != nil {
27+
fmt.Println(err)
28+
}
29+
}
30+
```
31+
32+
## Parameters
33+
34+
<Properties>
35+
<Property name="message" required type="map[string]interface{}">
36+
The data that will be sent to the submit
37+
</Property>
38+
</Properties>
39+
40+
## Examples
41+
42+
### Submit a job request
43+
44+
```go
45+
import (
46+
"context"
47+
"fmt"
48+
49+
"github.com/nitrictech/go-sdk/nitric"
50+
)
51+
52+
func main() {
53+
analyse, err := nitric.NewJob("analyse").Allow(nitric.JobSubmit)
54+
if err != nil {
55+
fmt.Println(err)
56+
}
57+
58+
analyse.Submit(context.TODO(), map[string]interface{}{
59+
"message": "message contents",
60+
})
61+
62+
if err := nitric.Run(); err != nil {
63+
fmt.Println(err)
64+
}
65+
}
66+
```

0 commit comments

Comments
 (0)