Skip to content

Latest commit

 

History

History
105 lines (73 loc) · 2.81 KB

File metadata and controls

105 lines (73 loc) · 2.81 KB

azure-timer-function-starter-typescript

Typescript starter for a timer-triggered (CRON job) Azure Function.

Motivation: I had some trouble setting up a local dev environment to run an Azure Function with a Timer trigger. Google and StackOverflow wisdom usually implies you're on Windows where Storage Emulator seems to be installed as part of a developer toolkit. On Mac and Linux it has to be installed; as well as some configuration has to be made.

The code in this repo is for a minimal function which is triggered every minute and prints the timer object passed by the Azure binding.

Typescript code is almost non-existent in the starter repo but I included linter and security check scripts as a best practice for the time when code grows.

Getting Started

Prerequisites

  • Node.js installed
  • Brew installed (Mac)

Installing

Install the Azure Functions Core Tools (Mac)

brew tap azure/functions
brew install azure-functions-core-tools@3

Install npm dependencies

npm i

Install Azurite - an open-source Azure Storage Emulator, which is going to replace the Storage Emulator.

There are a few ways to install it:

Choose whichever works best for you. After installation you should have Azurite running locally and listening on a port.

Configuration

For local development when using a storage emulator, UseDevelopmentStorage=true shortcut can be used.

It lives in the git-ignored local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true"
  }
}

Usage

Start the function app locally. It will trigger the function according to the schedule defined in cron-job/function.json. Here we have 0 */1 * * * * which is at the top of every minute.

npm run start

Alternatively you can run/debug the function in VS Code, for that you'd need to install Azure Functions for Visual Studio Code

Coding Style & Linter

Make sure code has no syntax errors and is properly formatted. Make sure docs are valid Markdown.

npm run lint

Security Checks

Make sure there are no known vulnerabilities in dependencies.

npm run audit-security

License

This project is licensed under the MIT License - see the LICENSE file for details