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

Commit 1dd8294

Browse files
add dart examples
1 parent 05afa54 commit 1dd8294

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/pages/batch.mdx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ Jobs can be used to read and write to/from all nitric resources, for example the
4040
Batches are defined similarly to services in a project's `nitric.yaml` file. For example:
4141

4242
```yaml
43-
batches:
43+
batch-services:
4444
- match: ./batches/*.ts
45-
start: yarn dev:batches $BATCH_PATH
45+
start: yarn dev:batches $SERVICE_PATH
4646
```
4747
4848
<Note>Batches can contain any number of Job Definitions.</Note>
@@ -83,6 +83,20 @@ async def generate_image(ctx: None):
8383
Nitric.run()
8484
```
8585

86+
```dart
87+
import 'package:nitric_sdk/nitric.dart';
88+
89+
void main() {
90+
final job = Nitric.job("batch-jobs");
91+
92+
job.handler((ctx) async {
93+
print("New job submitted for ${ctx.req.jobName}: ${ctx.req.message}");
94+
95+
return ctx;
96+
}, opts: JobResourceRequirements(cpus: 1, memory: 1024, gpus: 0));
97+
}
98+
```
99+
86100
</CodeGroup>
87101

88102
## Submitting Jobs for Execution
@@ -133,4 +147,21 @@ async def submit_job(ctx):
133147
Nitric.run()
134148
```
135149

150+
```dart
151+
import 'package:nitric_sdk/nitric.dart';
152+
153+
void main() {
154+
final api = Nitric.api("public");
155+
final analyze = Nitric.job("analyze").allow([JobPermission.submit]);
156+
157+
api.get("/submit-job", (ctx) async {
158+
analyze.submit({
159+
"someKey": "someValue"
160+
});
161+
162+
return ctx;
163+
});
164+
}
165+
```
166+
136167
</CodeGroup>

0 commit comments

Comments
 (0)