Python - job.handler()
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.
from nitric.resources import jobanalyze = job("analyze")@analyze(cpus=1, memory=2048, gpus=0)def do_analyze(data):# Run batch jobpass
Defining Batches
Batches are defined in different files to services and referenced in a project's nitric.yaml file. For example:
batch-services:- match: ./batches/*.pystart: pipenv run dev $SERVICE_PATH
Parameters
- Name
- cpus
- Optional
- Optional
- Type
- int
- Description
- The number of CPUs to allocate to the handler 
 
- Name
- gpus
- Optional
- Optional
- Type
- int
- Description
- The number of GPUs to allocate to the handler 
 
- Name
- memory
- Optional
- Optional
- Type
- int
- Description
- The amount of memory (MB) to allocate to the handler 
 
Examples
Define a job handler
from nitric.resources import jobanalyze = job("analyze")@analyze()def do_analyze(data):# Run batch jobpass
Create a job handler with custom resource requirements
from nitric.resources import jobanalyze = job("analyze")@analyze(cpus=1, memory=2048, gpus=0)def do_analyze(data):# Run batch jobpass
Last updated on Feb 4, 2025