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 job

analyze = job("analyze")

@analyze(cpus=1, memory=2048, gpus=0)
def do_analyze(data):
  # Run batch job
  pass

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/*.py
    start: 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 job

analyze = job("analyze")

@analyze()
def do_analyze(data):
  # Run batch job
  pass

Create a job handler with custom resource requirements

from nitric.resources import job

analyze = job("analyze")

@analyze(cpus=1, memory=2048, gpus=0)
def do_analyze(data):
  # Run batch job
  pass