0.2.1 • Published 6 months ago

nestjs-azure-func-trigger v0.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

Description

Azure Functions Trigger module for Nest.

This package works well together with @nestjs/azure-func-http which provides azure function http triggers for Nest.

This package provides a more general way to use any kind of azure function trigger ( timed, event bus, ...) for triggering methods of your Nest services.

Installation

Using npm:

$ npm install nestjs-azure-func-trigger

Tutorial

Adding a trigger is done by creating a new Azure Function in the app folder and then providing the createApp to the AzureFunctionTriggerAdapter.

import { InvocationContext } from '@azure/functions';
import { AzureFunctionTriggerAdapter } from 'nestjs-azure-func-trigger';
import { createApp } from '../src/main';

export default async function(context: InvocationContext): Promise<void> {
  return AzureFunctionTriggerAdapter.handle(createApp, context);
}

When the function is triggered it starts up and calls every service method that is annotated with AzureFunctionTrigger decorator that specified this function by the name parameter.

import { Injectable } from '@nestjs/common';

@Injectable()
class ClassWithTrigger {
  @AzureFunctionTrigger('FunctionName')
  public timerWithContext (
    @AzureFunctionContext() context: InvocationContext,
  ) {
    context.log('TimerWithContext', context);
  }
}

A function.json for this case looks like the following. Important is only the name of the function folder which in this case is "FunctionName"

{
  "bindings": [
    {
      "name": "trigger",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0,30 7-23 * * *"
    }
  ],
  "scriptFile": "../dist/FunctionName/index.js"
}
0.2.1

6 months ago

0.2.0

6 months ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago