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

Commit 486362a

Browse files
committed
WIP: Docs on jobs interface proposal.
1 parent 701e40c commit 486362a

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

src/pages/jobs.mdx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
export const description = 'Jobs'
2+
3+
# Jobs
4+
5+
Nitric provides functionality for provisioning long running batch workloads and High Performance Computing (HPC).
6+
7+
## Definitions
8+
9+
### Batch
10+
11+
A Batch is like a Nitric service, but is designed to be run as a single unit of work with a start and a finish.
12+
13+
### Job Definitions
14+
15+
Job defintions are defined as a part of batches and represent a single unit of work that work that can be run within a Nitric `Batch`
16+
17+
### Job
18+
19+
A Job is an instance of a Job Definition that is running within a `Batch`, these can be created from Nitric services or other Nitric batches.
20+
21+
## Limitations of Jobs
22+
23+
Jobs are designed to be long running HPC workloads and can take some time to spin up. They are not designed with reactivity in mind and are not suitable for responding to events from cloud resources.
24+
25+
Jobs are unable to run the following:
26+
- Topic Subscriptions
27+
- Bucket Notifications
28+
- API & HTTP resources
29+
- Websocket message handlers
30+
31+
Jobs can be use to read and write to/from all nitric resources.
32+
33+
## Defining a Job
34+
35+
<CodeGroup>
36+
37+
```typescript
38+
import { jobDefinition, JobContext } from '@nitric/sdk'
39+
40+
const myJob = jobDefinition('analyse').define((ctx: JobContext) => {
41+
// Do some work
42+
});
43+
```
44+
45+
```python
46+
from nitric.resources import job_definition
47+
from nitric.application import Nitric
48+
from nitric.context import JobContext
49+
50+
# Define will allow the developer to fine-tune the job option, such as adding resource dependencies (e.g. CPU, Memory, GPUs) etc.
51+
@job_definition("analyse").define()
52+
async def generate_image(ctx: None):
53+
# Do some work
54+
55+
56+
Nitric.run()
57+
```
58+
59+
</CodeGroup>
60+
61+
## Submitting Jobs for Execution
62+
63+
Jobs may be submitted from Nitric `services`.
64+
65+
<CodeGroup>
66+
67+
```javascript
68+
import * as nitric from '@nitric/sdk'
69+
70+
const api = nitric.api('public');
71+
const analyseJob = nitric.jobDefintion('analyse');
72+
73+
api.post('/submit-job', async (ctx) => {
74+
await analyseJob.submit({
75+
someKey: 'someValue'
76+
});
77+
});
78+
```
79+
80+
```python
81+
from nitric.resources import api, job_definition
82+
from nitric.application import Nitric
83+
84+
analyse_job = job_definition("analyse")
85+
public_api = api("public")
86+
87+
@public_api.post("/submit-job")
88+
async def submit_job(ctx):
89+
await analyse_job.submit({
90+
"someKey": "someValue"
91+
})
92+
93+
Nitric.run()
94+
```

0 commit comments

Comments
 (0)