Jobs
Nitric provides functionality for provisioning long running batch workloads and High Performance Computing (HPC).
Definitions
Batch
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.
Job Definitions
Job definitions are defined as a part of batches and represent a single unit of work that work that can be run within a Nitric Batch
Job
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.
Limitations of Batches
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.
Jobs are unable to run the following:
- Topic Subscriptions
- Bucket Notifications
- API & HTTP resources
- Websocket message handlers
Jobs can be used to read and write to/from all nitric resources.
Defining Batches
Batches are defined in a similar way to services, within the nitric.yaml
file. As an example
batches:
- match: ./batches/*.ts
start: yarn dev:batches $BATCH_PATH
A Batch can contain any number of Job Definitions.
Defining a Job
Within a Batch we define Job Definitions, which describes the code we will execute in each job.
import { jobDefinition, JobContext } from '@nitric/sdk'
const myJob = jobDefinition('analyse').define((ctx: JobContext) => {
// Do some work
})
Submitting Jobs for Execution
Jobs may be submitted from Nitric services
.
import * as nitric from '@nitric/sdk'
const api = nitric.api('public')
const analyseJob = nitric.jobDefintion('analyse')
api.post('/submit-job', async (ctx) => {
await analyseJob.submit({
someKey: 'someValue',
})
})