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

Commit 55602d8

Browse files
HomelessDinosaurjyecusch
authored andcommitted
add python, go, and nodejs
1 parent 19f8a15 commit 55602d8

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
@@ -1190,6 +1190,23 @@ const fullNav: FullNav = {
11901190
},
11911191
],
11921192
},
1193+
{
1194+
title: 'Batch Jobs',
1195+
links: [
1196+
{
1197+
title: 'job()',
1198+
href: '/reference/nodejs/batch/job',
1199+
},
1200+
{
1201+
title: 'job.handler()',
1202+
href: '/reference/nodejs/batch/job-handler',
1203+
},
1204+
{
1205+
title: 'job.send()',
1206+
href: '/reference/nodejs/batch/job-submit',
1207+
},
1208+
],
1209+
},
11931210
{
11941211
title: 'HTTP',
11951212
links: [
@@ -1656,6 +1673,23 @@ const fullNav: FullNav = {
16561673
},
16571674
],
16581675
},
1676+
{
1677+
title: 'Batch Jobs',
1678+
links: [
1679+
{
1680+
title: 'job()',
1681+
href: '/reference/python/batch/job',
1682+
},
1683+
{
1684+
title: 'job.handler()',
1685+
href: '/reference/python/batch/job-handler',
1686+
},
1687+
{
1688+
title: 'job.send()',
1689+
href: '/reference/python/batch/job-submit',
1690+
},
1691+
],
1692+
},
16591693
{
16601694
title: 'Key Value Stores',
16611695
links: [
@@ -1887,6 +1921,23 @@ const fullNav: FullNav = {
18871921
},
18881922
],
18891923
},
1924+
{
1925+
title: 'Batch Jobs',
1926+
links: [
1927+
{
1928+
title: 'job()',
1929+
href: '/reference/dart/batch/job',
1930+
},
1931+
{
1932+
title: 'job.handler()',
1933+
href: '/reference/dart/batch/job-handler',
1934+
},
1935+
{
1936+
title: 'job.send()',
1937+
href: '/reference/dart/batch/job-submit',
1938+
},
1939+
],
1940+
},
18901941
{
18911942
title: 'Key Value Stores',
18921943
links: [
@@ -2067,23 +2118,6 @@ const fullNav: FullNav = {
20672118
},
20682119
],
20692120
},
2070-
{
2071-
title: 'Batch Jobs',
2072-
links: [
2073-
{
2074-
title: 'job()',
2075-
href: '/reference/dart/batch/job',
2076-
},
2077-
{
2078-
title: 'job.handler()',
2079-
href: '/reference/dart/batch/job-handler',
2080-
},
2081-
{
2082-
title: 'job.send()',
2083-
href: '/reference/dart/batch/job-submit',
2084-
},
2085-
],
2086-
},
20872121
],
20882122
['reference/csharp']: [
20892123
{
@@ -2535,6 +2569,10 @@ const fullNav: FullNav = {
25352569
title: 'NewApi()',
25362570
href: '/reference/go/api/api',
25372571
},
2572+
{
2573+
title: 'NewJob()',
2574+
href: '/reference/go/batch/job',
2575+
},
25382576
{
25392577
title: 'NewKv()',
25402578
href: '/reference/go/keyvalue/keyvalue',
@@ -2618,6 +2656,19 @@ const fullNav: FullNav = {
26182656
},
26192657
],
26202658
},
2659+
{
2660+
title: 'Batch Jobs',
2661+
links: [
2662+
{
2663+
title: 'Job.Handler()',
2664+
href: '/reference/go/batch/job-handler',
2665+
},
2666+
{
2667+
title: 'Job.Send()',
2668+
href: '/reference/go/batch/job-submit',
2669+
},
2670+
],
2671+
},
26212672
{
26222673
title: 'Key Value Stores',
26232674
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)