0.1.7 • Published 1 year ago

@qstyler/nestjs-azure-func-trigger v0.1.7

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year 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 { Context } from '@azure/functions';
import { AzureFunctionTriggerAdapter } from 'nestjs-azure-func-trigger';
import { createApp } from '../src/main';

export default async function(context: Context): 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 (
    test: string,
    @AzureFunctionContext() context: Context,
  ) {
    context.log('TimerWithContext');
  }
}

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.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago