Dart - 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.
import 'package:nitric_sdk/nitric.dart';final analyze = Nitric.job("analyze").allow([JobPermission.submit]);analyze.handler((ctx) async {return ctx;}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0));
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/*.dartstart: dart run $SERVICE_PATH
Parameters
- Name
handler
- Required
- Required
- Type
- JobHandler
- Description
The middleware service to use as the handler for Job requests.
- Name
opts
- Optional
- Optional
- Type
- JobResourceRequirements
- Description
- 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
import 'package:nitric_sdk/nitric.dart';final analyze = Nitric.job("analyze").allow([JobPermission.submit]);analyze.handler((ctx) async {return ctx;});
Create a job handler with custom resource requirements
import 'package:nitric_sdk/nitric.dart';final analyze = Nitric.job("analyze").allow([JobPermission.submit]);analyze.handler((ctx) async {return ctx;}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 1));
Last updated on Nov 28, 2024