From bfa3635e347b7b7e224d19dd04c13edad6a9961b Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 15 Aug 2024 14:10:41 +1000 Subject: [PATCH 01/21] WIP: Docs on jobs interface proposal. --- src/pages/jobs.mdx | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/pages/jobs.mdx diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx new file mode 100644 index 000000000..4a8b72857 --- /dev/null +++ b/src/pages/jobs.mdx @@ -0,0 +1,94 @@ +export const description = 'Jobs' + +# 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 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` + +### 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 Jobs + +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 use to read and write to/from all nitric resources. + +## Defining a Job + + + +```typescript +import { jobDefinition, JobContext } from '@nitric/sdk' + +const myJob = jobDefinition('analyse').define((ctx: JobContext) => { + // Do some work +}); +``` + +```python +from nitric.resources import job_definition +from nitric.application import Nitric +from nitric.context import JobContext + +# Define will allow the developer to fine-tune the job option, such as adding resource dependencies (e.g. CPU, Memory, GPUs) etc. +@job_definition("analyse").define() +async def generate_image(ctx: None): + # Do some work + + +Nitric.run() +``` + + + +## Submitting Jobs for Execution + +Jobs may be submitted from Nitric `services`. + + + +```javascript +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' + }); +}); +``` + +```python +from nitric.resources import api, job_definition +from nitric.application import Nitric + +analyse_job = job_definition("analyse") +public_api = api("public") + +@public_api.post("/submit-job") +async def submit_job(ctx): + await analyse_job.submit({ + "someKey": "someValue" + }) + +Nitric.run() +``` \ No newline at end of file From f0c41c7bd0251ebf6f78967c644924aedaded7cd Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 15 Aug 2024 14:12:41 +1000 Subject: [PATCH 02/21] format. --- src/pages/jobs.mdx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index 4a8b72857..5de148d83 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -23,6 +23,7 @@ A Job is an instance of a Job Definition that is running within a `Batch`, these 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 @@ -38,8 +39,8 @@ Jobs can be use to read and write to/from all nitric resources. import { jobDefinition, JobContext } from '@nitric/sdk' const myJob = jobDefinition('analyse').define((ctx: JobContext) => { - // Do some work -}); + // Do some work +}) ``` ```python @@ -67,14 +68,14 @@ Jobs may be submitted from Nitric `services`. ```javascript import * as nitric from '@nitric/sdk' -const api = nitric.api('public'); -const analyseJob = nitric.jobDefintion('analyse'); +const api = nitric.api('public') +const analyseJob = nitric.jobDefintion('analyse') api.post('/submit-job', async (ctx) => { - await analyseJob.submit({ - someKey: 'someValue' - }); -}); + await analyseJob.submit({ + someKey: 'someValue', + }) +}) ``` ```python @@ -91,4 +92,4 @@ async def submit_job(ctx): }) Nitric.run() -``` \ No newline at end of file +``` From ae891989c92d654e79e67d982c34c8748c0be25e Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 15 Aug 2024 14:17:57 +1000 Subject: [PATCH 03/21] spellcheck. --- dictionary.txt | 1 + src/pages/jobs.mdx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dictionary.txt b/dictionary.txt index 16a8caf28..09a7ae08c 100644 --- a/dictionary.txt +++ b/dictionary.txt @@ -13,6 +13,7 @@ CORS ECR GCP GCR +HPC IAM OpenID JSON diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index 5de148d83..05e7ef508 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -12,7 +12,7 @@ A Batch is like a Nitric service, but is designed to be run as a single unit of ### Job Definitions -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` +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 From f024daafb4ac447a571806f8183e4541bc4d8de4 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 15 Aug 2024 14:24:41 +1000 Subject: [PATCH 04/21] fixes. --- src/nav.config.ts | 20 ++++++++++++++++++++ src/pages/jobs.mdx | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/nav.config.ts b/src/nav.config.ts index dc4005e52..151722931 100644 --- a/src/nav.config.ts +++ b/src/nav.config.ts @@ -4,6 +4,7 @@ import { ClockIcon, CloudIcon, CommandLineIcon, + CpuChipIcon, GlobeAltIcon, HomeIcon, LockClosedIcon, @@ -68,6 +69,11 @@ const buildingBlockLinks = [ href: '/http', icon: ServerIcon, }, + { + title: 'Jobs', + href: '/jobs', + icon: CpuChipIcon, + }, { title: 'Key Value Stores', href: '/keyvalue', @@ -694,6 +700,20 @@ const fullNav: FullNav = { links: buildingBlockLinks.filter((link) => link.href !== '/http'), }, ], + jobs: [ + { + links: [ + { + title: 'Overview', + href: '/jobs', + }, + ], + }, + { + title: 'More Building Blocks', + links: buildingBlockLinks.filter((link) => link.href !== '/jobs'), + }, + ], keyvalue: [ { links: [ diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index 05e7ef508..a5b2819e9 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -93,3 +93,5 @@ async def submit_job(ctx): Nitric.run() ``` + + \ No newline at end of file From aeb7e0d52e94aba3271fc40f5a210281f3dce148 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 15 Aug 2024 14:25:30 +1000 Subject: [PATCH 05/21] typo --- src/pages/jobs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index a5b2819e9..846c46984 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -29,7 +29,7 @@ Jobs are unable to run the following: - API & HTTP resources - Websocket message handlers -Jobs can be use to read and write to/from all nitric resources. +Jobs can be used to read and write to/from all nitric resources. ## Defining a Job From 8e684e312a971a9e46cf9f5915d0c1b18867ea8f Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 15 Aug 2024 14:29:33 +1000 Subject: [PATCH 06/21] Add defining batches. --- src/pages/jobs.mdx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index 846c46984..751740f6c 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -18,7 +18,7 @@ Job definitions are defined as a part of batches and represent a single unit of 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 Jobs +## 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. @@ -31,8 +31,22 @@ Jobs are unable to run the following: 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 + +```yaml +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. + ```typescript From 0789fb3f63e798cbf42eb932aa6fa3e3085a5985 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 15 Aug 2024 14:32:02 +1000 Subject: [PATCH 07/21] format. --- src/pages/jobs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index 751740f6c..3ae55fddd 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -108,4 +108,4 @@ async def submit_job(ctx): Nitric.run() ``` - \ No newline at end of file + From a4776cf1fe31573c8079b807db30b8d1c87018c6 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Tue, 20 Aug 2024 12:04:04 +1000 Subject: [PATCH 08/21] add resource defaults. --- src/pages/jobs.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index 3ae55fddd..31cac84fb 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -54,7 +54,7 @@ import { jobDefinition, JobContext } from '@nitric/sdk' const myJob = jobDefinition('analyse').define((ctx: JobContext) => { // Do some work -}) +}, {cpus: 1, memory: 1024, gpus: 0}) ``` ```python @@ -63,7 +63,7 @@ from nitric.application import Nitric from nitric.context import JobContext # Define will allow the developer to fine-tune the job option, such as adding resource dependencies (e.g. CPU, Memory, GPUs) etc. -@job_definition("analyse").define() +@job_definition("analyse").define(cpus=1, memory=1024, gpus=0) async def generate_image(ctx: None): # Do some work From 7c5d8dd62a049c3a5af1b0233a0aa4c709d2b630 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Tue, 20 Aug 2024 12:06:43 +1000 Subject: [PATCH 09/21] add resource overrides --- src/pages/jobs.mdx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index 31cac84fb..9ff5ee080 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -62,7 +62,6 @@ from nitric.resources import job_definition from nitric.application import Nitric from nitric.context import JobContext -# Define will allow the developer to fine-tune the job option, such as adding resource dependencies (e.g. CPU, Memory, GPUs) etc. @job_definition("analyse").define(cpus=1, memory=1024, gpus=0) async def generate_image(ctx: None): # Do some work @@ -86,9 +85,13 @@ const api = nitric.api('public') const analyseJob = nitric.jobDefintion('analyse') api.post('/submit-job', async (ctx) => { - await analyseJob.submit({ - someKey: 'someValue', - }) + await analyseJob.submit( + { + someKey: 'someValue', + }, + // optional job resource overrides + { cpus: 1, memory: 1024, gpus: 0 } + ) }) ``` @@ -101,9 +104,13 @@ public_api = api("public") @public_api.post("/submit-job") async def submit_job(ctx): - await analyse_job.submit({ + await analyse_job.submit( + { "someKey": "someValue" - }) + }, + # optional job resource overrides + { cpus: 1, memory: 1024, gpus: 0 } + ) Nitric.run() ``` From ed7b012d1680489ecaf03b1ee290b69e772f2ba5 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Tue, 20 Aug 2024 12:09:40 +1000 Subject: [PATCH 10/21] format. --- src/pages/jobs.mdx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx index 9ff5ee080..3df9dc570 100644 --- a/src/pages/jobs.mdx +++ b/src/pages/jobs.mdx @@ -52,9 +52,12 @@ Within a Batch we define Job Definitions, which describes the code we will execu ```typescript import { jobDefinition, JobContext } from '@nitric/sdk' -const myJob = jobDefinition('analyse').define((ctx: JobContext) => { - // Do some work -}, {cpus: 1, memory: 1024, gpus: 0}) +const myJob = jobDefinition('analyse').define( + (ctx: JobContext) => { + // Do some work + }, + { cpus: 1, memory: 1024, gpus: 0 } +) ``` ```python @@ -88,7 +91,7 @@ api.post('/submit-job', async (ctx) => { await analyseJob.submit( { someKey: 'someValue', - }, + }, // optional job resource overrides { cpus: 1, memory: 1024, gpus: 0 } ) From 2c63c1f4963667b1797f444bd690c915b60272fc Mon Sep 17 00:00:00 2001 From: Jye Cusch Date: Mon, 26 Aug 2024 12:33:53 +1000 Subject: [PATCH 11/21] edits --- src/nav.config.ts | 10 ++-- src/pages/batch.mdx | 136 ++++++++++++++++++++++++++++++++++++++++++++ src/pages/jobs.mdx | 121 --------------------------------------- 3 files changed, 141 insertions(+), 126 deletions(-) create mode 100644 src/pages/batch.mdx delete mode 100644 src/pages/jobs.mdx diff --git a/src/nav.config.ts b/src/nav.config.ts index 151722931..3c18d0f4f 100644 --- a/src/nav.config.ts +++ b/src/nav.config.ts @@ -70,8 +70,8 @@ const buildingBlockLinks = [ icon: ServerIcon, }, { - title: 'Jobs', - href: '/jobs', + title: 'AI & Batch', + href: '/batch', icon: CpuChipIcon, }, { @@ -700,18 +700,18 @@ const fullNav: FullNav = { links: buildingBlockLinks.filter((link) => link.href !== '/http'), }, ], - jobs: [ + batch: [ { links: [ { title: 'Overview', - href: '/jobs', + href: '/batch', }, ], }, { title: 'More Building Blocks', - links: buildingBlockLinks.filter((link) => link.href !== '/jobs'), + links: buildingBlockLinks.filter((link) => link.href !== '/batch'), }, ], keyvalue: [ diff --git a/src/pages/batch.mdx b/src/pages/batch.mdx new file mode 100644 index 000000000..03bfd0099 --- /dev/null +++ b/src/pages/batch.mdx @@ -0,0 +1,136 @@ +export const description = 'Running AI & Batch workloads with Nitric' + +# Batch + +Nitric provides functionality that allows you to run large-scale jobs in parallel across multiple virtual machines or compute resources. Unlike Nitric Services, which respond to real-time events (APIs, Schedules, etc.), Batch is intended to efficiently handle tasks that can be processed in batches, which means they don't need to run in real time but can be executed asynchronously. Batches can include tasks that require a lot of computing power, or access to GPU resources, such as machine learning model training, image processing, video transcoding, data processing, and data analysis. + +Nitric Batch is designed to be used in conjunction with Nitric Services, allowing you to run long-running, computationally intensive tasks in parallel with your real-time services. This allows you to build complex applications that can handle both real-time and batch processing workloads. + +Batches are deployed to cloud services such as [AWS Batch](https://aws.amazon.com/batch/), [Azure Batch](https://azure.microsoft.com/en-au/products/batch), and [Google Cloud Batch](https://cloud.google.com/batch/docs). Nitric abstracts the underlying cloud provider, allowing you to run your batch jobs on any of the supported cloud providers without having to worry about the specifics of each provider. + +## Definitions + +### Batch + +A Batch is similar to a Nitric Service, but it's intended for work with a definitive start and a finish. Where a service is designed to be reactive, a batch is designed to be proactive and run a series of jobs in parallel. + +### Job Definitions + +A Job Definition describes a type of work to be done by a Nitric `Batch` + +### Job + +A Job is an instance of a Job Definition that is running within a `Batch`, Jobs can be started from other Nitric Services or 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, for example they can publish new messages to a Topic, read and write to a Bucket, or read and write to a Database. They just can't respond to real-time events from these resources. + +## Defining Batches + +Batches are defined similarly to services in a project's `nitric.yaml` file. For example: + +```yaml +batches: + - match: ./batches/*.ts + start: yarn dev:batches $BATCH_PATH +``` + +Batches can contain any number of Job Definitions. + +## Defining a Job + +Within a Batch we create Job Definitions, by creating a new Job with a unique name and defining a handler function that will be executed when the job is submitted. + + + +```typescript +import { job, JobContext } from '@nitric/sdk' + +const myJob = job('analyse') + +// Use `handler` to register the callback function that will run when a job is submitted +myJob.handler( + async (ctx: JobContext) => { + // Do some work + }, + { cpus: 1, memory: 1024, gpus: 0 } +) +``` + +```python +from nitric.resources import job +from nitric.application import Nitric +from nitric.context import JobContext + +analyze = job("analyze") + +# Create the callback function that will run when a job is submitted +@analyze(cpus=1, memory=1024, gpus=0) +async def generate_image(ctx: None): + # Do some work + + +Nitric.run() +``` + + + +## Submitting Jobs for Execution + +Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function. + + + When submitting a job, you can optionally override the default resources + allocated to the job. + + + + +```javascript +import * as nitric from '@nitric/sdk' + +const api = nitric.api('public') +const analyze = nitric.job('analyze').allow('submit') + +api.post('/submit-job', async (ctx) => { + await analyze.submit( + { + someKey: 'someValue', + }, + // optional job resource overrides + { cpus: 1, memory: 1024, gpus: 0 } + ) +}) +``` + +```python +from nitric.resources import api, job +from nitric.application import Nitric + +analyze = job("analyze").allow("submit") +public_api = api("public") + +@public_api.post("/submit-job") +async def submit_job(ctx): + await analyze.submit( + { + "someKey": "someValue" + }, + # optional job resource overrides + { cpus: 1, memory: 1024, gpus: 0 } + ) + +Nitric.run() +``` + + diff --git a/src/pages/jobs.mdx b/src/pages/jobs.mdx deleted file mode 100644 index 3df9dc570..000000000 --- a/src/pages/jobs.mdx +++ /dev/null @@ -1,121 +0,0 @@ -export const description = 'Jobs' - -# 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 - -```yaml -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. - - - -```typescript -import { jobDefinition, JobContext } from '@nitric/sdk' - -const myJob = jobDefinition('analyse').define( - (ctx: JobContext) => { - // Do some work - }, - { cpus: 1, memory: 1024, gpus: 0 } -) -``` - -```python -from nitric.resources import job_definition -from nitric.application import Nitric -from nitric.context import JobContext - -@job_definition("analyse").define(cpus=1, memory=1024, gpus=0) -async def generate_image(ctx: None): - # Do some work - - -Nitric.run() -``` - - - -## Submitting Jobs for Execution - -Jobs may be submitted from Nitric `services`. - - - -```javascript -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', - }, - // optional job resource overrides - { cpus: 1, memory: 1024, gpus: 0 } - ) -}) -``` - -```python -from nitric.resources import api, job_definition -from nitric.application import Nitric - -analyse_job = job_definition("analyse") -public_api = api("public") - -@public_api.post("/submit-job") -async def submit_job(ctx): - await analyse_job.submit( - { - "someKey": "someValue" - }, - # optional job resource overrides - { cpus: 1, memory: 1024, gpus: 0 } - ) - -Nitric.run() -``` - - From b682a9cd1f1ee22d92aeb34623e545104ab4b103 Mon Sep 17 00:00:00 2001 From: Ryan Cartwright Date: Mon, 9 Sep 2024 18:20:02 +1000 Subject: [PATCH 12/21] add dart examples --- src/pages/batch.mdx | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/pages/batch.mdx b/src/pages/batch.mdx index 03bfd0099..14cb20cf3 100644 --- a/src/pages/batch.mdx +++ b/src/pages/batch.mdx @@ -40,9 +40,9 @@ Jobs can be used to read and write to/from all nitric resources, for example the Batches are defined similarly to services in a project's `nitric.yaml` file. For example: ```yaml -batches: +batch-services: - match: ./batches/*.ts - start: yarn dev:batches $BATCH_PATH + start: yarn dev:batches $SERVICE_PATH ``` Batches can contain any number of Job Definitions. @@ -83,6 +83,20 @@ async def generate_image(ctx: None): Nitric.run() ``` +```dart +import 'package:nitric_sdk/nitric.dart'; + +void main() { + final job = Nitric.job("batch-jobs"); + + job.handler((ctx) async { + print("New job submitted for ${ctx.req.jobName}: ${ctx.req.message}"); + + return ctx; + }, opts: JobResourceRequirements(cpus: 1, memory: 1024, gpus: 0)); +} +``` + ## Submitting Jobs for Execution @@ -133,4 +147,21 @@ async def submit_job(ctx): Nitric.run() ``` +```dart +import 'package:nitric_sdk/nitric.dart'; + +void main() { + final api = Nitric.api("public"); + final analyze = Nitric.job("analyze").allow([JobPermission.submit]); + + api.get("/submit-job", (ctx) async { + analyze.submit({ + "someKey": "someValue" + }); + + return ctx; + }); +} +``` + From b413abd0e3d51ed0610533f285cb3a5559309935 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Tue, 10 Sep 2024 12:19:47 +1000 Subject: [PATCH 13/21] remove resource overrides --- src/pages/batch.mdx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pages/batch.mdx b/src/pages/batch.mdx index 14cb20cf3..8dc7cacb0 100644 --- a/src/pages/batch.mdx +++ b/src/pages/batch.mdx @@ -60,10 +60,10 @@ const myJob = job('analyse') // Use `handler` to register the callback function that will run when a job is submitted myJob.handler( + { cpus: 1, memory: 1024, gpus: 0 }, async (ctx: JobContext) => { // Do some work }, - { cpus: 1, memory: 1024, gpus: 0 } ) ``` @@ -120,9 +120,7 @@ api.post('/submit-job', async (ctx) => { await analyze.submit( { someKey: 'someValue', - }, - // optional job resource overrides - { cpus: 1, memory: 1024, gpus: 0 } + } ) }) ``` @@ -139,9 +137,7 @@ async def submit_job(ctx): await analyze.submit( { "someKey": "someValue" - }, - # optional job resource overrides - { cpus: 1, memory: 1024, gpus: 0 } + } ) Nitric.run() From fa3470f4f83d33cc13a4e17238232329b28babef Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Tue, 10 Sep 2024 12:24:08 +1000 Subject: [PATCH 14/21] format --- src/pages/batch.mdx | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pages/batch.mdx b/src/pages/batch.mdx index 8dc7cacb0..0e43c7c74 100644 --- a/src/pages/batch.mdx +++ b/src/pages/batch.mdx @@ -59,12 +59,9 @@ import { job, JobContext } from '@nitric/sdk' const myJob = job('analyse') // Use `handler` to register the callback function that will run when a job is submitted -myJob.handler( - { cpus: 1, memory: 1024, gpus: 0 }, - async (ctx: JobContext) => { - // Do some work - }, -) +myJob.handler({ cpus: 1, memory: 1024, gpus: 0 }, async (ctx: JobContext) => { + // Do some work +}) ``` ```python @@ -117,11 +114,9 @@ const api = nitric.api('public') const analyze = nitric.job('analyze').allow('submit') api.post('/submit-job', async (ctx) => { - await analyze.submit( - { - someKey: 'someValue', - } - ) + await analyze.submit({ + someKey: 'someValue', + }) }) ``` From db7cd8417ee1d611cbddada8f5268427132296c8 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Tue, 10 Sep 2024 12:31:51 +1000 Subject: [PATCH 15/21] add transcoding. --- dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dictionary.txt b/dictionary.txt index 09a7ae08c..aaedcd23b 100644 --- a/dictionary.txt +++ b/dictionary.txt @@ -83,6 +83,7 @@ roadmap scaffolded scalable serverless +transcoding triages undeploy uuid From 19f8a15878e5d986fd2043381f998ab9f79d9bcf Mon Sep 17 00:00:00 2001 From: Ryan Cartwright Date: Tue, 24 Sep 2024 16:04:48 +1000 Subject: [PATCH 16/21] add dart reference --- src/nav.config.ts | 17 +++++ src/pages/batch.mdx | 5 -- .../reference/dart/batch/job-handler.mdx | 71 +++++++++++++++++++ src/pages/reference/dart/batch/job-submit.mdx | 34 +++++++++ src/pages/reference/dart/batch/job.mdx | 39 ++++++++++ 5 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 src/pages/reference/dart/batch/job-handler.mdx create mode 100644 src/pages/reference/dart/batch/job-submit.mdx create mode 100644 src/pages/reference/dart/batch/job.mdx diff --git a/src/nav.config.ts b/src/nav.config.ts index 3c18d0f4f..a83fd325d 100644 --- a/src/nav.config.ts +++ b/src/nav.config.ts @@ -2067,6 +2067,23 @@ const fullNav: FullNav = { }, ], }, + { + title: 'Batch Jobs', + links: [ + { + title: 'job()', + href: '/reference/dart/batch/job', + }, + { + title: 'job.handler()', + href: '/reference/dart/batch/job-handler', + }, + { + title: 'job.send()', + href: '/reference/dart/batch/job-submit', + }, + ], + }, ], ['reference/csharp']: [ { diff --git a/src/pages/batch.mdx b/src/pages/batch.mdx index 0e43c7c74..ee0bdb854 100644 --- a/src/pages/batch.mdx +++ b/src/pages/batch.mdx @@ -100,11 +100,6 @@ void main() { Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function. - - When submitting a job, you can optionally override the default resources - allocated to the job. - - ```javascript diff --git a/src/pages/reference/dart/batch/job-handler.mdx b/src/pages/reference/dart/batch/job-handler.mdx new file mode 100644 index 000000000..a70f72714 --- /dev/null +++ b/src/pages/reference/dart/batch/job-handler.mdx @@ -0,0 +1,71 @@ +export const description = + "Reference for Nitric's Dart library - Register a job handler to with the Nitric Dart SDK" + +# 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. + +```dart +import 'package:nitric_sdk/nitric.dart'; + +final analyse = Nitric.job("analyse").allow([JobPermission.submit]); + +analyse.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: + +```yaml +batch-services: + - match: ./batches/*.dart + start: dart run $SERVICE_PATH +``` + +## Parameters + + + + The middleware service to use as the handler for Job requests. + + + + The number of CPUs to allocate to the handler + + + The number of GPUs to allocate to the handler + + + The amount of memory (MB) to allocate to the handler + + + + +## Examples + +### Define a job handler + +```dart +import 'package:nitric_sdk/nitric.dart'; + +final analyse = Nitric.job("analyse").allow([JobPermission.submit]); + +analyse.handler((ctx) async { + return ctx; +}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0)); +``` + +### Create a job handler with custom resource requirements + +```dart +import 'package:nitric_sdk/nitric.dart'; + +final analyse = Nitric.job("analyse").allow([JobPermission.submit]); + +analyse.handler((ctx) async { + return ctx; +}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0)); +``` diff --git a/src/pages/reference/dart/batch/job-submit.mdx b/src/pages/reference/dart/batch/job-submit.mdx new file mode 100644 index 000000000..849632e69 --- /dev/null +++ b/src/pages/reference/dart/batch/job-submit.mdx @@ -0,0 +1,34 @@ +export const description = + "Reference for Nitric's Dart library - Submit a batch job request with the Nitric Dart SDK" + +# Dart - job.submit()() + +Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function. + +```dart +import 'package:nitric_sdk/nitric.dart'; + +final analyse = Nitric.job("analyse").allow([JobPermission.submit]); + +await analyse.submit({ message: "message contents" }); +``` + +## Parameters + + + + The data that will be sent to the submit + + + +## Examples + +### Submit a job request + +```dart +import 'package:nitric_sdk/nitric.dart'; + +final analyse = Nitric.job("analyse").allow([JobPermission.submit]); + +await analyse.submit({ message: "data contents" }); +``` diff --git a/src/pages/reference/dart/batch/job.mdx b/src/pages/reference/dart/batch/job.mdx new file mode 100644 index 000000000..00933a4bf --- /dev/null +++ b/src/pages/reference/dart/batch/job.mdx @@ -0,0 +1,39 @@ +export const description = + "Reference for Nitric's Dart library - Create Batch Jobs with the Nitric Dart SDK" + +# Dart - job() + +Creates a new Batch Job. + +```dart +import 'package:nitric_sdk/nitric.dart'; + +final analyse = Nitric.job("analyse"); +``` + +## Parameters + + + + The unique name of this Batch Job within the app. Subsequent calls to `job` + with the same name will return the same object. + + + +## Examples + +### Create a Job + +```dart +import 'package:nitric_sdk/nitric.dart'; + +final analyse = Nitric.job("analyse"); +``` + +### Create a Job with permissions to submit jobs + +```dart +import 'package:nitric_sdk/nitric.dart'; + +final analyse = Nitric.job("analyse").allow([JobPermission.submit]); +``` From 55602d82d50048f4fb304a2df4df4ee51ad936e1 Mon Sep 17 00:00:00 2001 From: Ryan Cartwright Date: Thu, 26 Sep 2024 00:10:57 +1000 Subject: [PATCH 17/21] add python, go, and nodejs --- src/nav.config.ts | 85 ++++++++++--- .../reference/dart/batch/job-handler.mdx | 10 +- src/pages/reference/dart/batch/job-submit.mdx | 2 +- src/pages/reference/go/batch/job-handler.mdx | 112 ++++++++++++++++++ src/pages/reference/go/batch/job-submit.mdx | 66 +++++++++++ src/pages/reference/go/batch/job.mdx | 72 +++++++++++ .../reference/nodejs/batch/job-handler.mdx | 75 ++++++++++++ .../reference/nodejs/batch/job-submit.mdx | 34 ++++++ src/pages/reference/nodejs/batch/job.mdx | 39 ++++++ .../reference/python/batch/job-handler.mdx | 69 +++++++++++ .../reference/python/batch/job-submit.mdx | 34 ++++++ src/pages/reference/python/batch/job.mdx | 39 ++++++ 12 files changed, 614 insertions(+), 23 deletions(-) create mode 100644 src/pages/reference/go/batch/job-handler.mdx create mode 100644 src/pages/reference/go/batch/job-submit.mdx create mode 100644 src/pages/reference/go/batch/job.mdx create mode 100644 src/pages/reference/nodejs/batch/job-handler.mdx create mode 100644 src/pages/reference/nodejs/batch/job-submit.mdx create mode 100644 src/pages/reference/nodejs/batch/job.mdx create mode 100644 src/pages/reference/python/batch/job-handler.mdx create mode 100644 src/pages/reference/python/batch/job-submit.mdx create mode 100644 src/pages/reference/python/batch/job.mdx diff --git a/src/nav.config.ts b/src/nav.config.ts index a83fd325d..17b723d30 100644 --- a/src/nav.config.ts +++ b/src/nav.config.ts @@ -1190,6 +1190,23 @@ const fullNav: FullNav = { }, ], }, + { + title: 'Batch Jobs', + links: [ + { + title: 'job()', + href: '/reference/nodejs/batch/job', + }, + { + title: 'job.handler()', + href: '/reference/nodejs/batch/job-handler', + }, + { + title: 'job.send()', + href: '/reference/nodejs/batch/job-submit', + }, + ], + }, { title: 'HTTP', links: [ @@ -1656,6 +1673,23 @@ const fullNav: FullNav = { }, ], }, + { + title: 'Batch Jobs', + links: [ + { + title: 'job()', + href: '/reference/python/batch/job', + }, + { + title: 'job.handler()', + href: '/reference/python/batch/job-handler', + }, + { + title: 'job.send()', + href: '/reference/python/batch/job-submit', + }, + ], + }, { title: 'Key Value Stores', links: [ @@ -1887,6 +1921,23 @@ const fullNav: FullNav = { }, ], }, + { + title: 'Batch Jobs', + links: [ + { + title: 'job()', + href: '/reference/dart/batch/job', + }, + { + title: 'job.handler()', + href: '/reference/dart/batch/job-handler', + }, + { + title: 'job.send()', + href: '/reference/dart/batch/job-submit', + }, + ], + }, { title: 'Key Value Stores', links: [ @@ -2067,23 +2118,6 @@ const fullNav: FullNav = { }, ], }, - { - title: 'Batch Jobs', - links: [ - { - title: 'job()', - href: '/reference/dart/batch/job', - }, - { - title: 'job.handler()', - href: '/reference/dart/batch/job-handler', - }, - { - title: 'job.send()', - href: '/reference/dart/batch/job-submit', - }, - ], - }, ], ['reference/csharp']: [ { @@ -2535,6 +2569,10 @@ const fullNav: FullNav = { title: 'NewApi()', href: '/reference/go/api/api', }, + { + title: 'NewJob()', + href: '/reference/go/batch/job', + }, { title: 'NewKv()', href: '/reference/go/keyvalue/keyvalue', @@ -2618,6 +2656,19 @@ const fullNav: FullNav = { }, ], }, + { + title: 'Batch Jobs', + links: [ + { + title: 'Job.Handler()', + href: '/reference/go/batch/job-handler', + }, + { + title: 'Job.Send()', + href: '/reference/go/batch/job-submit', + }, + ], + }, { title: 'Key Value Stores', links: [ diff --git a/src/pages/reference/dart/batch/job-handler.mdx b/src/pages/reference/dart/batch/job-handler.mdx index a70f72714..665b87042 100644 --- a/src/pages/reference/dart/batch/job-handler.mdx +++ b/src/pages/reference/dart/batch/job-handler.mdx @@ -32,13 +32,13 @@ batch-services: The middleware service to use as the handler for Job requests. - + The number of CPUs to allocate to the handler - + The number of GPUs to allocate to the handler - + The amount of memory (MB) to allocate to the handler @@ -55,7 +55,7 @@ final analyse = Nitric.job("analyse").allow([JobPermission.submit]); analyse.handler((ctx) async { return ctx; -}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0)); +}); ``` ### Create a job handler with custom resource requirements @@ -67,5 +67,5 @@ final analyse = Nitric.job("analyse").allow([JobPermission.submit]); analyse.handler((ctx) async { return ctx; -}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0)); +}, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 1)); ``` diff --git a/src/pages/reference/dart/batch/job-submit.mdx b/src/pages/reference/dart/batch/job-submit.mdx index 849632e69..0c61a25f6 100644 --- a/src/pages/reference/dart/batch/job-submit.mdx +++ b/src/pages/reference/dart/batch/job-submit.mdx @@ -1,7 +1,7 @@ export const description = "Reference for Nitric's Dart library - Submit a batch job request with the Nitric Dart SDK" -# Dart - job.submit()() +# Dart - job.submit() Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function. diff --git a/src/pages/reference/go/batch/job-handler.mdx b/src/pages/reference/go/batch/job-handler.mdx new file mode 100644 index 000000000..668f8db4f --- /dev/null +++ b/src/pages/reference/go/batch/job-handler.mdx @@ -0,0 +1,112 @@ +export const description = + "Reference for Nitric's Go library - Register a job handler to with the Nitric Go SDK" + +# Go - 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. + +```go +import ( + "fmt" + + "github.com/nitrictech/go-sdk/nitric" + "github.com/nitrictech/go-sdk/nitric/batch" +) + +func main() { + analyse := nitric.NewJob("analyse") + + analyse.Handler(nitric.JobResourceRequirements{ + Cpus: 1, + Memory: 2048, + Gpus: 0, + }, func(ctx *batch.Ctx) { + // do long running work + }) + + if err := nitric.Run(); err != nil { + fmt.Println(err) + } +} +``` + +## Defining Batches + +Batches are defined in different files to services and referenced in a project's `nitric.yaml` file. For example: + +```yaml +batch-services: + - match: ./batches/*.go + start: go run $SERVICE_PATH +``` + +## Parameters + + + + The middleware service to use as the handler for Job requests. + + + + The number of CPUs to allocate to the handler + + + The number of GPUs to allocate to the handler + + + The amount of memory (MB) to allocate to the handler + + + + +## Examples + +### Define a job handler + +```go +import ( + "fmt" + + "github.com/nitrictech/go-sdk/nitric" + "github.com/nitrictech/go-sdk/nitric/batch" +) + +func main() { + analyse := nitric.NewJob("analyse") + + analyse.Handler(nitric.JobResourceRequirements{}, func(ctx *batch.Ctx) { + // do long running work + }) + + if err := nitric.Run(); err != nil { + fmt.Println(err) + } +} +``` + +### Create a job handler with custom resource requirements + +```go +import ( + "fmt" + + "github.com/nitrictech/go-sdk/nitric" + "github.com/nitrictech/go-sdk/nitric/batch" +) + +func main() { + analyse := nitric.NewJob("analyse") + + analyse.Handler(nitric.JobResourceRequirements{ + Cpus: 1, + Memory: 2048, + Gpus: 0, + }, func(ctx *batch.Ctx) { + // do long running work + }) + + if err := nitric.Run(); err != nil { + fmt.Println(err) + } +} +``` diff --git a/src/pages/reference/go/batch/job-submit.mdx b/src/pages/reference/go/batch/job-submit.mdx new file mode 100644 index 000000000..2e365d30f --- /dev/null +++ b/src/pages/reference/go/batch/job-submit.mdx @@ -0,0 +1,66 @@ +export const description = + "Reference for Nitric's Go library - Submit a batch job request with the Nitric Go SDK" + +# Go - job.submit() + +Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function. + +```go +import ( + "context" + "fmt" + + "github.com/nitrictech/go-sdk/nitric" +) + +func main() { + analyse, err := nitric.NewJob("analyse").Allow(nitric.JobSubmit) + if err != nil { + fmt.Println(err) + } + + analyse.Submit(context.TODO(), map[string]interface{}{ + "message": "message contents", + }) + + if err := nitric.Run(); err != nil { + fmt.Println(err) + } +} +``` + +## Parameters + + + + The data that will be sent to the submit + + + +## Examples + +### Submit a job request + +```go +import ( + "context" + "fmt" + + "github.com/nitrictech/go-sdk/nitric" +) + +func main() { + analyse, err := nitric.NewJob("analyse").Allow(nitric.JobSubmit) + if err != nil { + fmt.Println(err) + } + + analyse.Submit(context.TODO(), map[string]interface{}{ + "message": "message contents", + }) + + if err := nitric.Run(); err != nil { + fmt.Println(err) + } +} +``` diff --git a/src/pages/reference/go/batch/job.mdx b/src/pages/reference/go/batch/job.mdx new file mode 100644 index 000000000..daf7a0670 --- /dev/null +++ b/src/pages/reference/go/batch/job.mdx @@ -0,0 +1,72 @@ +export const description = + "Reference for Nitric's Go library - Create Batch Jobs with the Nitric Go SDK" + +# Go - job() + +Creates a new Batch Job. + +```go +import ( + "fmt" + + "github.com/nitrictech/go-sdk/nitric" +) + +func main() { + analyse := nitric.NewJob("analyse") + + if err := nitric.Run(); err != nil { + fmt.Println(err) + } +} +``` + +## Parameters + + + + The unique name of this Batch Job within the app. Subsequent calls to `job` + with the same name will return the same object. + + + +## Examples + +### Create a Job + +```go +import ( + "fmt" + + "github.com/nitrictech/go-sdk/nitric" +) + +func main() { + analyse := nitric.NewJob("analyse") + + if err := nitric.Run(); err != nil { + fmt.Println(err) + } +} +``` + +### Create a Job with permissions to submit jobs + +```go +import ( + "fmt" + + "github.com/nitrictech/go-sdk/nitric" +) + +func main() { + analyse, err := nitric.NewJob("analyse").Allow(nitric.JobSubmit) + if err != nil { + fmt.Println(err) + } + + if err := nitric.Run(); err != nil { + fmt.Println(err) + } +} +``` diff --git a/src/pages/reference/nodejs/batch/job-handler.mdx b/src/pages/reference/nodejs/batch/job-handler.mdx new file mode 100644 index 000000000..83d52cdca --- /dev/null +++ b/src/pages/reference/nodejs/batch/job-handler.mdx @@ -0,0 +1,75 @@ +export const description = + "Reference for Nitric's Node.js library - Register a job handler" + +# Node.js - 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. + +```ts +import { job, JobContext } from '@nitric/sdk' + +const analyse = job('analyse') + +analyse.handler({ cpus: 1, memory: 1024, gpus: 0 }, async (ctx: JobContext) => { + // Do some work + return ctx +}) +``` + +## Defining Batches + +Batches are defined in different files to services and referenced in a project's `nitric.yaml` file. For example: + +```yaml +batch-services: + - match: ./services/*.ts + start: yarn dev:services $SERVICE_PATH +``` + +## Parameters + + + + One or more middleware services to use as the handler which will run on the + defined frequency. + + + + The number of CPUs to allocate to the handler + + + The number of GPUs to allocate to the handler + + + The amount of memory (MB) to allocate to the handler + + + + +## Examples + +### Define a job handler with default resource requirements + +```ts +import { job, JobContext } from '@nitric/sdk' + +const analyse = job('analyse') + +analyse.handler({}, async (ctx: JobContext) => { + // Do some work + return ctx +}) +``` + +### Create a job handler with custom resource requirements + +```ts +import { job, JobContext } from '@nitric/sdk' + +const analyse = job('analyse') + +analyse.handler({ cpus: 1, memory: 2048, gpus: 0 }, async (ctx: JobContext) => { + // Do some work + return ctx +}) +``` diff --git a/src/pages/reference/nodejs/batch/job-submit.mdx b/src/pages/reference/nodejs/batch/job-submit.mdx new file mode 100644 index 000000000..1c21febe1 --- /dev/null +++ b/src/pages/reference/nodejs/batch/job-submit.mdx @@ -0,0 +1,34 @@ +export const description = + "Reference for Nitric's Node.js library - Submit a batch job request with custom resource requirements" + +# Node.js - job.submit() + +Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function. + +```ts +import { job } from '@nitric/sdk' + +const analyse = job('analyse').allow('submit') + +await analyse.submit({ message: 'message contents' }) +``` + +## Parameters + + + + The data that will be sent to the submit + + + +## Examples + +### Submit a job request + +```ts +import { job } from '@nitric/sdk' + +const analyse = job('analyse').allow('submit') + +await analyse.submit({ message: 'message contents' }) +``` diff --git a/src/pages/reference/nodejs/batch/job.mdx b/src/pages/reference/nodejs/batch/job.mdx new file mode 100644 index 000000000..2af176dc8 --- /dev/null +++ b/src/pages/reference/nodejs/batch/job.mdx @@ -0,0 +1,39 @@ +export const description = + "Reference for Nitric's Node.js library - Create Batch Jobs" + +# Node.js - job() + +Creates a new Batch Job. + +```ts +import { job } from '@nitric/sdk' + +const analyse = job('analyse') +``` + +## Parameters + + + + The unique name of this Batch Job within the app. Subsequent calls to `job` + with the same name will return the same object. + + + +## Examples + +### Create a Job + +```ts +import { job } from '@nitric/sdk' + +const analyse = job('analyse') +``` + +### Create a Job with permissions to submit jobs + +```ts +import { job } from '@nitric/sdk' + +const analyse = job('analyse').allow('submit') +``` diff --git a/src/pages/reference/python/batch/job-handler.mdx b/src/pages/reference/python/batch/job-handler.mdx new file mode 100644 index 000000000..a49b49130 --- /dev/null +++ b/src/pages/reference/python/batch/job-handler.mdx @@ -0,0 +1,69 @@ +export const description = + "Reference for Nitric's Python library - Register a job handler to with the Nitric Python SDK" + +# 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. + +```python +from nitric.resources import job + +analyse = job("analyse") + +@analyse(cpus=1, memory=2048, gpus=0) +def do_analyse(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: + +```yaml +batch-services: + - match: ./batches/*.py + start: pipenv run dev $SERVICE_PATH +``` + +## Parameters + + + + The number of CPUs to allocate to the handler + + + The number of GPUs to allocate to the handler + + + The amount of memory (MB) to allocate to the handler + + + +## Examples + +### Define a job handler + +```python +from nitric.resources import job + +analyse = job("analyse") + +@analyse() +def do_analyse(data): + # Run batch job + pass +``` + +### Create a job handler with custom resource requirements + +```python +from nitric.resources import job + +analyse = job("analyse") + +@analyse(cpus=1, memory=2048, gpus=0) +def do_analyse(data): + # Run batch job + pass +``` diff --git a/src/pages/reference/python/batch/job-submit.mdx b/src/pages/reference/python/batch/job-submit.mdx new file mode 100644 index 000000000..2585cec88 --- /dev/null +++ b/src/pages/reference/python/batch/job-submit.mdx @@ -0,0 +1,34 @@ +export const description = + "Reference for Nitric's Dart library - Submit a batch job request with the Nitric Python SDK" + +# Python - job.submit() + +Jobs may be submitted from Nitric `services` or other `batches` using the `submit` method on the job reference. When submitting a job you can provide a payload that will be passed to the job handler function. + +```python +from nitric.resources import job + +analyse = job("analyse").allow("submit") + +await analyse.submit({ "message": "message contents" }) +``` + +## Parameters + + + + The data that will be sent to the submit + + + +## Examples + +### Submit a job request + +```python +from nitric.resources import job + +analyse = job("analyse").allow("submit") + +await analyse.submit({ "message": "message contents" }) +``` diff --git a/src/pages/reference/python/batch/job.mdx b/src/pages/reference/python/batch/job.mdx new file mode 100644 index 000000000..9aed84d05 --- /dev/null +++ b/src/pages/reference/python/batch/job.mdx @@ -0,0 +1,39 @@ +export const description = + "Reference for Nitric's Python library - Create Batch Jobs with the Nitric Python SDK" + +# Python - job() + +Creates a new Batch Job. + +```python +from nitric.resources import job + +analyse = job("analyse") +``` + +## Parameters + + + + The unique name of this Batch Job within the app. Subsequent calls to `job` + with the same name will return the same object. + + + +## Examples + +### Create a Job + +```python +from nitric.resources import job + +analyse = job("analyse") +``` + +### Create a Job with permissions to submit jobs + +```python +from nitric.resources import job + +analyse = job("analyse").allow("submit") +``` From 4baaa53d095167cb99fa73c3ad565a502c472a20 Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 3 Oct 2024 16:52:30 +1000 Subject: [PATCH 18/21] update nodejs handler docs --- src/pages/reference/nodejs/batch/job-handler.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/reference/nodejs/batch/job-handler.mdx b/src/pages/reference/nodejs/batch/job-handler.mdx index 83d52cdca..6dc7fa79b 100644 --- a/src/pages/reference/nodejs/batch/job-handler.mdx +++ b/src/pages/reference/nodejs/batch/job-handler.mdx @@ -10,10 +10,10 @@ import { job, JobContext } from '@nitric/sdk' const analyse = job('analyse') -analyse.handler({ cpus: 1, memory: 1024, gpus: 0 }, async (ctx: JobContext) => { +analyse.handler(async (ctx: JobContext) => { // Do some work return ctx -}) +}, { cpus: 1, memory: 1024, gpus: 0 }) ``` ## Defining Batches @@ -55,7 +55,7 @@ import { job, JobContext } from '@nitric/sdk' const analyse = job('analyse') -analyse.handler({}, async (ctx: JobContext) => { +analyse.handler(async (ctx: JobContext) => { // Do some work return ctx }) @@ -68,8 +68,8 @@ import { job, JobContext } from '@nitric/sdk' const analyse = job('analyse') -analyse.handler({ cpus: 1, memory: 2048, gpus: 0 }, async (ctx: JobContext) => { +analyse.handler(async (ctx: JobContext) => { // Do some work return ctx -}) +}, { cpus: 1, memory: 2048, gpus: 0 }) ``` From b47aab7893f0dc02bc248f8f84ffd0b4b9251b7d Mon Sep 17 00:00:00 2001 From: Tim Holm Date: Thu, 3 Oct 2024 16:55:19 +1000 Subject: [PATCH 19/21] update nodejs example --- src/pages/batch.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/batch.mdx b/src/pages/batch.mdx index ee0bdb854..69c35fb25 100644 --- a/src/pages/batch.mdx +++ b/src/pages/batch.mdx @@ -59,9 +59,9 @@ import { job, JobContext } from '@nitric/sdk' const myJob = job('analyse') // Use `handler` to register the callback function that will run when a job is submitted -myJob.handler({ cpus: 1, memory: 1024, gpus: 0 }, async (ctx: JobContext) => { +myJob.handler(async (ctx: JobContext) => { // Do some work -}) +}, { cpus: 1, memory: 1024, gpus: 0 }) ``` ```python From c2766f2b532bfde6c94c21a4e3c0dfe17a79b438 Mon Sep 17 00:00:00 2001 From: Ryan Cartwright Date: Thu, 3 Oct 2024 17:01:04 +1000 Subject: [PATCH 20/21] change all analyse -> analyze --- src/pages/batch.mdx | 13 +++++--- .../reference/dart/batch/job-handler.mdx | 12 +++---- src/pages/reference/dart/batch/job-submit.mdx | 8 ++--- src/pages/reference/dart/batch/job.mdx | 6 ++-- src/pages/reference/go/batch/job-handler.mdx | 12 +++---- src/pages/reference/go/batch/job-submit.mdx | 8 ++--- src/pages/reference/go/batch/job.mdx | 6 ++-- .../reference/nodejs/batch/job-handler.mdx | 32 +++++++++++-------- .../reference/nodejs/batch/job-submit.mdx | 8 ++--- src/pages/reference/nodejs/batch/job.mdx | 6 ++-- .../reference/python/batch/job-handler.mdx | 18 +++++------ .../reference/python/batch/job-submit.mdx | 8 ++--- src/pages/reference/python/batch/job.mdx | 6 ++-- 13 files changed, 76 insertions(+), 67 deletions(-) diff --git a/src/pages/batch.mdx b/src/pages/batch.mdx index 69c35fb25..c2e0480f3 100644 --- a/src/pages/batch.mdx +++ b/src/pages/batch.mdx @@ -56,12 +56,15 @@ Within a Batch we create Job Definitions, by creating a new Job with a unique na ```typescript import { job, JobContext } from '@nitric/sdk' -const myJob = job('analyse') +const analyze = job('analyze') // Use `handler` to register the callback function that will run when a job is submitted -myJob.handler(async (ctx: JobContext) => { - // Do some work -}, { cpus: 1, memory: 1024, gpus: 0 }) +analyze.handler( + async (ctx: JobContext) => { + // Do some work + }, + { cpus: 1, memory: 1024, gpus: 0 } +) ``` ```python @@ -84,7 +87,7 @@ Nitric.run() import 'package:nitric_sdk/nitric.dart'; void main() { - final job = Nitric.job("batch-jobs"); + final job = Nitric.job("analyze"); job.handler((ctx) async { print("New job submitted for ${ctx.req.jobName}: ${ctx.req.message}"); diff --git a/src/pages/reference/dart/batch/job-handler.mdx b/src/pages/reference/dart/batch/job-handler.mdx index 665b87042..5f2786b75 100644 --- a/src/pages/reference/dart/batch/job-handler.mdx +++ b/src/pages/reference/dart/batch/job-handler.mdx @@ -8,9 +8,9 @@ Job handlers are the code that is run when a job request is submitted. These han ```dart import 'package:nitric_sdk/nitric.dart'; -final analyse = Nitric.job("analyse").allow([JobPermission.submit]); +final analyze = Nitric.job("analyze").allow([JobPermission.submit]); -analyse.handler((ctx) async { +analyze.handler((ctx) async { return ctx; }, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 0)); ``` @@ -51,9 +51,9 @@ batch-services: ```dart import 'package:nitric_sdk/nitric.dart'; -final analyse = Nitric.job("analyse").allow([JobPermission.submit]); +final analyze = Nitric.job("analyze").allow([JobPermission.submit]); -analyse.handler((ctx) async { +analyze.handler((ctx) async { return ctx; }); ``` @@ -63,9 +63,9 @@ analyse.handler((ctx) async { ```dart import 'package:nitric_sdk/nitric.dart'; -final analyse = Nitric.job("analyse").allow([JobPermission.submit]); +final analyze = Nitric.job("analyze").allow([JobPermission.submit]); -analyse.handler((ctx) async { +analyze.handler((ctx) async { return ctx; }, opts: JobResourceRequirements(cpus: 1, memory: 2048, gpus: 1)); ``` diff --git a/src/pages/reference/dart/batch/job-submit.mdx b/src/pages/reference/dart/batch/job-submit.mdx index 0c61a25f6..00faf1a9a 100644 --- a/src/pages/reference/dart/batch/job-submit.mdx +++ b/src/pages/reference/dart/batch/job-submit.mdx @@ -8,9 +8,9 @@ Jobs may be submitted from Nitric `services` or other `batches` using the `submi ```dart import 'package:nitric_sdk/nitric.dart'; -final analyse = Nitric.job("analyse").allow([JobPermission.submit]); +final analyze = Nitric.job("analyze").allow([JobPermission.submit]); -await analyse.submit({ message: "message contents" }); +await analyze.submit({ message: "message contents" }); ``` ## Parameters @@ -28,7 +28,7 @@ await analyse.submit({ message: "message contents" }); ```dart import 'package:nitric_sdk/nitric.dart'; -final analyse = Nitric.job("analyse").allow([JobPermission.submit]); +final analyze = Nitric.job("analyze").allow([JobPermission.submit]); -await analyse.submit({ message: "data contents" }); +await analyze.submit({ message: "data contents" }); ``` diff --git a/src/pages/reference/dart/batch/job.mdx b/src/pages/reference/dart/batch/job.mdx index 00933a4bf..cb551f9a0 100644 --- a/src/pages/reference/dart/batch/job.mdx +++ b/src/pages/reference/dart/batch/job.mdx @@ -8,7 +8,7 @@ Creates a new Batch Job. ```dart import 'package:nitric_sdk/nitric.dart'; -final analyse = Nitric.job("analyse"); +final analyze = Nitric.job("analyze"); ``` ## Parameters @@ -27,7 +27,7 @@ final analyse = Nitric.job("analyse"); ```dart import 'package:nitric_sdk/nitric.dart'; -final analyse = Nitric.job("analyse"); +final analyze = Nitric.job("analyze"); ``` ### Create a Job with permissions to submit jobs @@ -35,5 +35,5 @@ final analyse = Nitric.job("analyse"); ```dart import 'package:nitric_sdk/nitric.dart'; -final analyse = Nitric.job("analyse").allow([JobPermission.submit]); +final analyze = Nitric.job("analyze").allow([JobPermission.submit]); ``` diff --git a/src/pages/reference/go/batch/job-handler.mdx b/src/pages/reference/go/batch/job-handler.mdx index 668f8db4f..c9dcf9ee7 100644 --- a/src/pages/reference/go/batch/job-handler.mdx +++ b/src/pages/reference/go/batch/job-handler.mdx @@ -14,9 +14,9 @@ import ( ) func main() { - analyse := nitric.NewJob("analyse") + analyze := nitric.NewJob("analyze") - analyse.Handler(nitric.JobResourceRequirements{ + analyze.Handler(nitric.JobResourceRequirements{ Cpus: 1, Memory: 2048, Gpus: 0, @@ -72,9 +72,9 @@ import ( ) func main() { - analyse := nitric.NewJob("analyse") + analyze := nitric.NewJob("analyze") - analyse.Handler(nitric.JobResourceRequirements{}, func(ctx *batch.Ctx) { + analyze.Handler(nitric.JobResourceRequirements{}, func(ctx *batch.Ctx) { // do long running work }) @@ -95,9 +95,9 @@ import ( ) func main() { - analyse := nitric.NewJob("analyse") + analyze := nitric.NewJob("analyze") - analyse.Handler(nitric.JobResourceRequirements{ + analyze.Handler(nitric.JobResourceRequirements{ Cpus: 1, Memory: 2048, Gpus: 0, diff --git a/src/pages/reference/go/batch/job-submit.mdx b/src/pages/reference/go/batch/job-submit.mdx index 2e365d30f..6c8e9a474 100644 --- a/src/pages/reference/go/batch/job-submit.mdx +++ b/src/pages/reference/go/batch/job-submit.mdx @@ -14,12 +14,12 @@ import ( ) func main() { - analyse, err := nitric.NewJob("analyse").Allow(nitric.JobSubmit) + analyze, err := nitric.NewJob("analyze").Allow(nitric.JobSubmit) if err != nil { fmt.Println(err) } - analyse.Submit(context.TODO(), map[string]interface{}{ + analyze.Submit(context.TODO(), map[string]interface{}{ "message": "message contents", }) @@ -50,12 +50,12 @@ import ( ) func main() { - analyse, err := nitric.NewJob("analyse").Allow(nitric.JobSubmit) + analyze, err := nitric.NewJob("analyze").Allow(nitric.JobSubmit) if err != nil { fmt.Println(err) } - analyse.Submit(context.TODO(), map[string]interface{}{ + analyze.Submit(context.TODO(), map[string]interface{}{ "message": "message contents", }) diff --git a/src/pages/reference/go/batch/job.mdx b/src/pages/reference/go/batch/job.mdx index daf7a0670..ac45113d6 100644 --- a/src/pages/reference/go/batch/job.mdx +++ b/src/pages/reference/go/batch/job.mdx @@ -13,7 +13,7 @@ import ( ) func main() { - analyse := nitric.NewJob("analyse") + analyze := nitric.NewJob("analyze") if err := nitric.Run(); err != nil { fmt.Println(err) @@ -42,7 +42,7 @@ import ( ) func main() { - analyse := nitric.NewJob("analyse") + analyze := nitric.NewJob("analyze") if err := nitric.Run(); err != nil { fmt.Println(err) @@ -60,7 +60,7 @@ import ( ) func main() { - analyse, err := nitric.NewJob("analyse").Allow(nitric.JobSubmit) + analyze, err := nitric.NewJob("analyze").Allow(nitric.JobSubmit) if err != nil { fmt.Println(err) } diff --git a/src/pages/reference/nodejs/batch/job-handler.mdx b/src/pages/reference/nodejs/batch/job-handler.mdx index 6dc7fa79b..547a70f5b 100644 --- a/src/pages/reference/nodejs/batch/job-handler.mdx +++ b/src/pages/reference/nodejs/batch/job-handler.mdx @@ -8,12 +8,15 @@ Job handlers are the code that is run when a job request is submitted. These han ```ts import { job, JobContext } from '@nitric/sdk' -const analyse = job('analyse') - -analyse.handler(async (ctx: JobContext) => { - // Do some work - return ctx -}, { cpus: 1, memory: 1024, gpus: 0 }) +const analyze = job('analyze') + +analyze.handler( + async (ctx: JobContext) => { + // Do some work + return ctx + }, + { cpus: 1, memory: 1024, gpus: 0 } +) ``` ## Defining Batches @@ -53,9 +56,9 @@ batch-services: ```ts import { job, JobContext } from '@nitric/sdk' -const analyse = job('analyse') +const analyze = job('analyze') -analyse.handler(async (ctx: JobContext) => { +analyze.handler(async (ctx: JobContext) => { // Do some work return ctx }) @@ -66,10 +69,13 @@ analyse.handler(async (ctx: JobContext) => { ```ts import { job, JobContext } from '@nitric/sdk' -const analyse = job('analyse') +const analyze = job('analyze') -analyse.handler(async (ctx: JobContext) => { - // Do some work - return ctx -}, { cpus: 1, memory: 2048, gpus: 0 }) +analyze.handler( + async (ctx: JobContext) => { + // Do some work + return ctx + }, + { cpus: 1, memory: 2048, gpus: 0 } +) ``` diff --git a/src/pages/reference/nodejs/batch/job-submit.mdx b/src/pages/reference/nodejs/batch/job-submit.mdx index 1c21febe1..84a95712c 100644 --- a/src/pages/reference/nodejs/batch/job-submit.mdx +++ b/src/pages/reference/nodejs/batch/job-submit.mdx @@ -8,9 +8,9 @@ Jobs may be submitted from Nitric `services` or other `batches` using the `submi ```ts import { job } from '@nitric/sdk' -const analyse = job('analyse').allow('submit') +const analyze = job('analyze').allow('submit') -await analyse.submit({ message: 'message contents' }) +await analyze.submit({ message: 'message contents' }) ``` ## Parameters @@ -28,7 +28,7 @@ await analyse.submit({ message: 'message contents' }) ```ts import { job } from '@nitric/sdk' -const analyse = job('analyse').allow('submit') +const analyze = job('analyze').allow('submit') -await analyse.submit({ message: 'message contents' }) +await analyze.submit({ message: 'message contents' }) ``` diff --git a/src/pages/reference/nodejs/batch/job.mdx b/src/pages/reference/nodejs/batch/job.mdx index 2af176dc8..a83dcd619 100644 --- a/src/pages/reference/nodejs/batch/job.mdx +++ b/src/pages/reference/nodejs/batch/job.mdx @@ -8,7 +8,7 @@ Creates a new Batch Job. ```ts import { job } from '@nitric/sdk' -const analyse = job('analyse') +const analyze = job('analyze') ``` ## Parameters @@ -27,7 +27,7 @@ const analyse = job('analyse') ```ts import { job } from '@nitric/sdk' -const analyse = job('analyse') +const analyze = job('analyze') ``` ### Create a Job with permissions to submit jobs @@ -35,5 +35,5 @@ const analyse = job('analyse') ```ts import { job } from '@nitric/sdk' -const analyse = job('analyse').allow('submit') +const analyze = job('analyze').allow('submit') ``` diff --git a/src/pages/reference/python/batch/job-handler.mdx b/src/pages/reference/python/batch/job-handler.mdx index a49b49130..ced99bd87 100644 --- a/src/pages/reference/python/batch/job-handler.mdx +++ b/src/pages/reference/python/batch/job-handler.mdx @@ -8,10 +8,10 @@ Job handlers are the code that is run when a job request is submitted. These han ```python from nitric.resources import job -analyse = job("analyse") +analyze = job("analyze") -@analyse(cpus=1, memory=2048, gpus=0) -def do_analyse(data): +@analyze(cpus=1, memory=2048, gpus=0) +def do_analyze(data): # Run batch job pass ``` @@ -47,10 +47,10 @@ batch-services: ```python from nitric.resources import job -analyse = job("analyse") +analyze = job("analyze") -@analyse() -def do_analyse(data): +@analyze() +def do_analyze(data): # Run batch job pass ``` @@ -60,10 +60,10 @@ def do_analyse(data): ```python from nitric.resources import job -analyse = job("analyse") +analyze = job("analyze") -@analyse(cpus=1, memory=2048, gpus=0) -def do_analyse(data): +@analyze(cpus=1, memory=2048, gpus=0) +def do_analyze(data): # Run batch job pass ``` diff --git a/src/pages/reference/python/batch/job-submit.mdx b/src/pages/reference/python/batch/job-submit.mdx index 2585cec88..be34bd24b 100644 --- a/src/pages/reference/python/batch/job-submit.mdx +++ b/src/pages/reference/python/batch/job-submit.mdx @@ -8,9 +8,9 @@ Jobs may be submitted from Nitric `services` or other `batches` using the `submi ```python from nitric.resources import job -analyse = job("analyse").allow("submit") +analyze = job("analyze").allow("submit") -await analyse.submit({ "message": "message contents" }) +await analyze.submit({ "message": "message contents" }) ``` ## Parameters @@ -28,7 +28,7 @@ await analyse.submit({ "message": "message contents" }) ```python from nitric.resources import job -analyse = job("analyse").allow("submit") +analyze = job("analyze").allow("submit") -await analyse.submit({ "message": "message contents" }) +await analyze.submit({ "message": "message contents" }) ``` diff --git a/src/pages/reference/python/batch/job.mdx b/src/pages/reference/python/batch/job.mdx index 9aed84d05..7b5b6ba79 100644 --- a/src/pages/reference/python/batch/job.mdx +++ b/src/pages/reference/python/batch/job.mdx @@ -8,7 +8,7 @@ Creates a new Batch Job. ```python from nitric.resources import job -analyse = job("analyse") +analyze = job("analyze") ``` ## Parameters @@ -27,7 +27,7 @@ analyse = job("analyse") ```python from nitric.resources import job -analyse = job("analyse") +analyze = job("analyze") ``` ### Create a Job with permissions to submit jobs @@ -35,5 +35,5 @@ analyse = job("analyse") ```python from nitric.resources import job -analyse = job("analyse").allow("submit") +analyze = job("analyze").allow("submit") ``` From 1ddf3eeb6353c4d27d01c3da343fb00850321836 Mon Sep 17 00:00:00 2001 From: Jye Cusch Date: Thu, 3 Oct 2024 17:09:01 +1000 Subject: [PATCH 21/21] fix go batch docs --- src/pages/batch.mdx | 58 ++++++++++++++++++- src/pages/reference/go/batch/job-handler.mdx | 44 ++++---------- src/pages/reference/go/batch/job-submit.mdx | 22 ++----- src/pages/reference/go/batch/job.mdx | 28 +++------ .../reference/preview-features/index.mdx | 1 + 5 files changed, 84 insertions(+), 69 deletions(-) diff --git a/src/pages/batch.mdx b/src/pages/batch.mdx index c2e0480f3..d056a5913 100644 --- a/src/pages/batch.mdx +++ b/src/pages/batch.mdx @@ -4,10 +4,25 @@ export const description = 'Running AI & Batch workloads with Nitric' Nitric provides functionality that allows you to run large-scale jobs in parallel across multiple virtual machines or compute resources. Unlike Nitric Services, which respond to real-time events (APIs, Schedules, etc.), Batch is intended to efficiently handle tasks that can be processed in batches, which means they don't need to run in real time but can be executed asynchronously. Batches can include tasks that require a lot of computing power, or access to GPU resources, such as machine learning model training, image processing, video transcoding, data processing, and data analysis. + + Batches are currently in [Preview](/reference/preview-features) and are + currently only available in the following languages: JavaScript, Python, Go, + and Dart, using the nitric/aws@1.14.0, nitric/gcp@1.14.0 or later. + + Nitric Batch is designed to be used in conjunction with Nitric Services, allowing you to run long-running, computationally intensive tasks in parallel with your real-time services. This allows you to build complex applications that can handle both real-time and batch processing workloads. Batches are deployed to cloud services such as [AWS Batch](https://aws.amazon.com/batch/), [Azure Batch](https://azure.microsoft.com/en-au/products/batch), and [Google Cloud Batch](https://cloud.google.com/batch/docs). Nitric abstracts the underlying cloud provider, allowing you to run your batch jobs on any of the supported cloud providers without having to worry about the specifics of each provider. +## Enabling Batches + +Batches are currently in [Preview](/reference/preview-features). To enable this feature in your project add the following to your `nitric.yaml` file + +```yaml +preview: + - batch-services +``` + ## Definitions ### Batch @@ -42,7 +57,7 @@ Batches are defined similarly to services in a project's `nitric.yaml` file. For ```yaml batch-services: - match: ./batches/*.ts - start: yarn dev:batches $SERVICE_PATH + start: yarn dev:services $SERVICE_PATH ``` Batches can contain any number of Job Definitions. @@ -83,6 +98,24 @@ async def generate_image(ctx: None): Nitric.run() ``` +```go +import ( + "github.com/nitrictech/go-sdk/nitric" + "github.com/nitrictech/go-sdk/nitric/batch" +) + +func main() { + analyze := nitric.NewJob("analyze") + + // Use `Handler` to register the callback function that will run when a job is submitted + analyze.Handler(func(ctx *batch.Ctx) { + // Do some work + }, batch.WithCpus(1), batch.WithMemory(1024), batch.WithGpus(0)) + + nitric.Run() +} +``` + ```dart import 'package:nitric_sdk/nitric.dart'; @@ -136,6 +169,29 @@ async def submit_job(ctx): Nitric.run() ``` +```go +import ( + "context" + + "github.com/nitrictech/go-sdk/nitric" + "github.com/nitrictech/go-sdk/nitric/apis" + "github.com/nitrictech/go-sdk/nitric/batch" +) + +func main() { + api := nitric.NewApi("public") + analyze := nitric.NewJob("analyze").Allow(batch.JobSubmit) + + api.Post("/submit-job", func(ctx *apis.Ctx) { + analyze.Submit(context.Background(), map[string]interface{}{ + "someKey": "someValue", + }) + }) + + nitric.Run() +} +``` + ```dart import 'package:nitric_sdk/nitric.dart'; diff --git a/src/pages/reference/go/batch/job-handler.mdx b/src/pages/reference/go/batch/job-handler.mdx index c9dcf9ee7..ddc8f1473 100644 --- a/src/pages/reference/go/batch/job-handler.mdx +++ b/src/pages/reference/go/batch/job-handler.mdx @@ -7,8 +7,6 @@ Job handlers are the code that is run when a job request is submitted. These han ```go import ( - "fmt" - "github.com/nitrictech/go-sdk/nitric" "github.com/nitrictech/go-sdk/nitric/batch" ) @@ -16,17 +14,11 @@ import ( func main() { analyze := nitric.NewJob("analyze") - analyze.Handler(nitric.JobResourceRequirements{ - Cpus: 1, - Memory: 2048, - Gpus: 0, - }, func(ctx *batch.Ctx) { + analyse.Handler(func(ctx *batch.Ctx) { // do long running work - }) + }, batch.WithCpus(1), batch.WithMemory(2048), batch.WithGpus(1)) - if err := nitric.Run(); err != nil { - fmt.Println(err) - } + nitric.Run() } ``` @@ -46,14 +38,14 @@ batch-services: The middleware service to use as the handler for Job requests. - - + + The number of CPUs to allocate to the handler - + The number of GPUs to allocate to the handler - + The amount of memory (MB) to allocate to the handler @@ -65,8 +57,6 @@ batch-services: ```go import ( - "fmt" - "github.com/nitrictech/go-sdk/nitric" "github.com/nitrictech/go-sdk/nitric/batch" ) @@ -74,13 +64,11 @@ import ( func main() { analyze := nitric.NewJob("analyze") - analyze.Handler(nitric.JobResourceRequirements{}, func(ctx *batch.Ctx) { + analyse.Handler(func(ctx *batch.Ctx) { // do long running work }) - if err := nitric.Run(); err != nil { - fmt.Println(err) - } + nitric.Run() } ``` @@ -88,8 +76,6 @@ func main() { ```go import ( - "fmt" - "github.com/nitrictech/go-sdk/nitric" "github.com/nitrictech/go-sdk/nitric/batch" ) @@ -97,16 +83,10 @@ import ( func main() { analyze := nitric.NewJob("analyze") - analyze.Handler(nitric.JobResourceRequirements{ - Cpus: 1, - Memory: 2048, - Gpus: 0, - }, func(ctx *batch.Ctx) { + analyse.Handler(func(ctx *batch.Ctx) { // do long running work - }) + }, batch.WithCpus(1), batch.WithMemory(2048), batch.WithGpus(1)) - if err := nitric.Run(); err != nil { - fmt.Println(err) - } + nitric.Run() } ``` diff --git a/src/pages/reference/go/batch/job-submit.mdx b/src/pages/reference/go/batch/job-submit.mdx index 6c8e9a474..834e0c859 100644 --- a/src/pages/reference/go/batch/job-submit.mdx +++ b/src/pages/reference/go/batch/job-submit.mdx @@ -8,24 +8,19 @@ Jobs may be submitted from Nitric `services` or other `batches` using the `submi ```go import ( "context" - "fmt" "github.com/nitrictech/go-sdk/nitric" + "github.com/nitrictech/go-sdk/nitric/batch" ) func main() { - analyze, err := nitric.NewJob("analyze").Allow(nitric.JobSubmit) - if err != nil { - fmt.Println(err) - } + analyse := nitric.NewJob("analyse").Allow(batch.JobSubmit) analyze.Submit(context.TODO(), map[string]interface{}{ "message": "message contents", }) - if err := nitric.Run(); err != nil { - fmt.Println(err) - } + nitric.Run() } ``` @@ -44,23 +39,18 @@ func main() { ```go import ( "context" - "fmt" "github.com/nitrictech/go-sdk/nitric" + "github.com/nitrictech/go-sdk/nitric/batch" ) func main() { - analyze, err := nitric.NewJob("analyze").Allow(nitric.JobSubmit) - if err != nil { - fmt.Println(err) - } + analyse := nitric.NewJob("analyse").Allow(batch.JobSubmit) analyze.Submit(context.TODO(), map[string]interface{}{ "message": "message contents", }) - if err := nitric.Run(); err != nil { - fmt.Println(err) - } + nitric.Run() } ``` diff --git a/src/pages/reference/go/batch/job.mdx b/src/pages/reference/go/batch/job.mdx index ac45113d6..b2001e857 100644 --- a/src/pages/reference/go/batch/job.mdx +++ b/src/pages/reference/go/batch/job.mdx @@ -7,17 +7,13 @@ Creates a new Batch Job. ```go import ( - "fmt" - "github.com/nitrictech/go-sdk/nitric" ) func main() { analyze := nitric.NewJob("analyze") - if err := nitric.Run(); err != nil { - fmt.Println(err) - } + nitric.Run() } ``` @@ -36,37 +32,29 @@ func main() { ```go import ( - "fmt" - "github.com/nitrictech/go-sdk/nitric" ) func main() { analyze := nitric.NewJob("analyze") - if err := nitric.Run(); err != nil { - fmt.Println(err) - } + nitric.Run() } ``` ### Create a Job with permissions to submit jobs ```go -import ( - "fmt" +package main +import ( "github.com/nitrictech/go-sdk/nitric" + "github.com/nitrictech/go-sdk/nitric/batch" ) func main() { - analyze, err := nitric.NewJob("analyze").Allow(nitric.JobSubmit) - if err != nil { - fmt.Println(err) - } - - if err := nitric.Run(); err != nil { - fmt.Println(err) - } + analyse := nitric.NewJob("analyse").Allow(batch.JobSubmit) + + nitric.Run() } ``` diff --git a/src/pages/reference/preview-features/index.mdx b/src/pages/reference/preview-features/index.mdx index 5fdcc4625..6705cddf5 100644 --- a/src/pages/reference/preview-features/index.mdx +++ b/src/pages/reference/preview-features/index.mdx @@ -15,6 +15,7 @@ Each preview feature will have its own documentation page, which will include in | ------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | | [docker-providers](/reference/providers/install/docker) | CLI v1.39.0 | [feedback](https://github.com/nitrictech/nitric/issues/605) | | [sql-databases](/sql) | CLI v1.42.0
AWS Provider v1.6.0
Azure Provider v1.9.0
AWS Terraform Provider v1.8.0 | [feedback](https://github.com/nitrictech/cli/issues/732) | +| [batch-services](/batch) | CLI v1.54.0
AWS Provider v1.14.0
GCP Provider v1.14.0 | [feedback]( | ## Released Preview Features