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

Commit 8a24e44

Browse files
add dart reference
1 parent f566f91 commit 8a24e44

File tree

5 files changed

+161
-5
lines changed

5 files changed

+161
-5
lines changed

src/nav.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,23 @@ const fullNav: FullNav = {
20632063
},
20642064
],
20652065
},
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+
},
20662083
],
20672084
['reference/csharp']: [
20682085
{

src/pages/batch.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ void main() {
100100

101101
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.
102102

103-
<Note>
104-
When submitting a job, you can optionally override the default resources
105-
allocated to the job.
106-
</Note>
107-
108103
<CodeGroup>
109104

110105
```javascript
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
export const description =
2+
"Reference for Nitric's Dart library - Register a job handler to with the Nitric Dart SDK"
3+
4+
# Dart - 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+
```dart
9+
import 'package:nitric_sdk/nitric.dart';
10+
11+
final analyse = Nitric.job("analyse").allow([JobPermission.submit]);
12+
13+
analyse.handler((ctx) async {
14+
return ctx;
15+
}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0));
16+
```
17+
18+
## Defining Batches
19+
20+
Batches are defined in different files to services and referenced in a project's `nitric.yaml` file. For example:
21+
22+
```yaml
23+
batch-services:
24+
- match: ./batches/*.dart
25+
start: dart run $SERVICE_PATH
26+
```
27+
28+
## Parameters
29+
30+
<Properties>
31+
<Property name="handler" required type="JobHandler">
32+
The middleware service to use as the handler for Job requests.
33+
</Property>
34+
<Property name="opts" type="JobResourceRequirements" nested>
35+
<Property name="cpus">
36+
The number of CPUs to allocate to the handler
37+
</Property>
38+
<Property name="gpus">
39+
The number of GPUs to allocate to the handler
40+
</Property>
41+
<Property name="memory">
42+
The amount of memory (MB) to allocate to the handler
43+
</Property>
44+
</Property>
45+
</Properties>
46+
47+
## Examples
48+
49+
### Define a job handler
50+
51+
```dart
52+
import 'package:nitric_sdk/nitric.dart';
53+
54+
final analyse = Nitric.job("analyse").allow([JobPermission.submit]);
55+
56+
analyse.handler((ctx) async {
57+
return ctx;
58+
}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0));
59+
```
60+
61+
### Create a job handler with custom resource requirements
62+
63+
```dart
64+
import 'package:nitric_sdk/nitric.dart';
65+
66+
final analyse = Nitric.job("analyse").allow([JobPermission.submit]);
67+
68+
analyse.handler((ctx) async {
69+
return ctx;
70+
}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0));
71+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export const description =
2+
"Reference for Nitric's Dart library - Submit a batch job request with the Nitric Dart SDK"
3+
4+
# Dart - 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+
```dart
9+
import 'package:nitric_sdk/nitric.dart';
10+
11+
final analyse = Nitric.job("analyse").allow([JobPermission.submit]);
12+
13+
await analyse.submit({ message: "message contents" });
14+
```
15+
16+
## Parameters
17+
18+
<Properties>
19+
<Property name="message" required type="Map<String, dynamic>">
20+
The data that will be sent to the submit
21+
</Property>
22+
</Properties>
23+
24+
## Examples
25+
26+
### Submit a job request
27+
28+
```dart
29+
import 'package:nitric_sdk/nitric.dart';
30+
31+
final analyse = Nitric.job("analyse").allow([JobPermission.submit]);
32+
33+
await analyse.submit({ message: "data contents" });
34+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export const description =
2+
"Reference for Nitric's Dart library - Create Batch Jobs with the Nitric Dart SDK"
3+
4+
# Dart - job()
5+
6+
Creates a new Batch Job.
7+
8+
```dart
9+
import 'package:nitric_sdk/nitric.dart';
10+
11+
final analyse = Nitric.job("analyse");
12+
```
13+
14+
## Parameters
15+
16+
<Properties>
17+
<Property name="name" required type="String">
18+
The unique name of this Batch Job within the app. Subsequent calls to `job`
19+
with the same name will return the same object.
20+
</Property>
21+
</Properties>
22+
23+
## Examples
24+
25+
### Create a Job
26+
27+
```dart
28+
import 'package:nitric_sdk/nitric.dart';
29+
30+
final analyse = Nitric.job("analyse");
31+
```
32+
33+
### Create a Job with permissions to submit jobs
34+
35+
```dart
36+
import 'package:nitric_sdk/nitric.dart';
37+
38+
final analyse = Nitric.job("analyse").allow([JobPermission.submit]);
39+
```

0 commit comments

Comments
 (0)