How to use durable-functions - 10 common examples

To help you get started, we’ve selected a few durable-functions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rcarmo / azure-durable-functions-node-blog-engine / renderPipeline / index.js View on Github external
extensions: ['.md', '.mkd', '.markdown'],
                pipeline: ['renderMarkdownActivity', 'renderTemplateActivity']
            },
            renderTextileActivity: {
                extensions: ['.text', '.textile'],
                pipeline: ['renderTextileActivity', 'renderTemplateActivity']
            },
           /* Render HTML snippets directly (disabled to allow custom content pass-through)
            renderTemplateActivity: {
                extensions: ['.htm', '.html'],
                pipeline: ['renderTemplateActivity']
            }
            */
        };

module.exports = df.orchestrator(function* (context) {
    const outputs = [],
          name = context.df.getInput(),
          extension = path.extname(name);

    var pipeline = ["copyActivity"],
        currentItem = name;

    // context.log("pipeline:", pipeline, name, extension);

    Object.keys(activityMap).forEach(key => { 
        if(activityMap[key].extensions.includes(extension)) {
            pipeline = activityMap[key].pipeline;
        }
    })

    // all activities we build should return a JS object
github Azure / azure-functions-durable-js / samples / E4_SmsPhoneVerification / index.js View on Github external
const df = require("durable-functions");
const moment = require('moment');

module.exports = df.orchestrator(function*(context) {
    const phoneNumber = context.df.getInput();
    if (!phoneNumber) {
        throw "A phone number input is required.";
    }

    const challengeCode = yield context.df.callActivity("E4_SendSmsChallenge", phoneNumber);

    // The user has 90 seconds to respond with the code they received in the SMS message.
    const expiration = moment.utc(context.df.currentUtcDateTime).add(90, 's');
    const timeoutTask = context.df.createTimer(expiration.toDate());

    let authorized = false;
    for (let i = 0; i <= 3; i++) {
        const challengeResponseTask = context.df.waitForExternalEvent("SmsChallengeResponse");

        const winner = yield context.df.Task.any([challengeResponseTask, timeoutTask]);
github Azure-Samples / durablefunctions-apiscraping-nodejs / FanOutFanInCrawler / Orchestrator / index.js View on Github external
const df = require('durable-functions')

module.exports = df.orchestrator(function* (context) {
  // retrieves the organization name from the Orchestrator_HttpStart function
  var organizationName = context.df.getInput();
  
  // retrieves the list of repositories for an organization by invoking a separate Activity Function.
  var repositories = yield context.df.callActivity('GetAllRepositoriesForOrganization', organizationName);

  // Creates an array of task to store the result of each functions
  var output = []
  for (var i = 0; i < repositories.length; i++) {
    // Starting a `GetOpenedIssues` activity WITHOUT `yield`
    // This will starts Activity Functions in parallel instead of sequentially.
    output.push(
      context.df.callActivity('GetOpenedIssues', repositories[i])
    )
  }
github Azure / azure-functions-durable-extension / samples / javascript / E3_Monitor / index.js View on Github external
const df = require("durable-functions");
const moment = require('moment');

module.exports = df.orchestrator(function*(context) {
    const input = context.df.getInput();
    context.log("Received monitor request. location: " + (input ? input.location : undefined)
        + ". phone: " + (input ? input.phone : undefined) + ".");

    verifyRequest(input);

    const endTime = moment.utc(context.df.currentUtcDateTime).add(6, 'h');
    context.log("Instantiating monitor for " + input.location.city + ", " + input.location.state
        + ". Expires: " + (endTime) + ".");

    while (moment.utc(context.df.currentUtcDateTime).isBefore(endTime)) {
        // Check the weather
        context.log("Checking current weather conditions for " + input.location.city + ", "
            + input.location.state + " at " + context.df.currentUtcDateTime + ".");
        const isClear = yield context.df.callActivity("E3_GetIsClear", input.location);
github Azure / azure-functions-durable-js / samples / E2_BackupSiteContent / index.js View on Github external
const df = require("durable-functions");

module.exports = df.orchestrator(function*(context){
    const rootDirectory = context.df.getInput();
    if (!rootDirectory) {
        throw new Error("A directory path is required as an input.");
    }

    const files = yield context.df.callActivity("E2_GetFileList", rootDirectory);

    // Backup Files and save Promises into array
    const tasks = [];
    for (const file of files) {
        tasks.push(context.df.callActivity("E2_CopyFileToBlob", file));
    }

    // wait for all the Backup Files Activities to complete, sum total bytes
    const results = yield context.df.Task.all(tasks);
    const totalBytes = results.reduce((prev, curr) => prev + curr, 0);
github Azure / azure-functions-durable-js / samples / ContinueAsNewCounter / index.js View on Github external
const df = require("durable-functions");
const moment = require('moment');

module.exports = df.orchestrator(function*(context) {
    let currentValue = context.df.getInput() || 0;
    context.log(`Value is ${currentValue}`);
    currentValue++;

    var wait = moment.utc(context.df.currentUtcDateTime).add(30, 's');
    context.log("Counting up at" + wait.toString());
    yield context.df.createTimer(wait.toDate());

    if (currentValue < 10) {
        yield context.df.continueAsNew(currentValue);
    }

    return currentValue;
});
github christiannwamba / calendar-app / serverless / scheduleOrchestrator / index.js View on Github external
/*
 * This function is not intended to be invoked directly. Instead it will be
 * triggered by an HTTP starter function.
 * 
 * Before running this sample, please:
 * - create a Durable activity function (default name is "Hello")
 * - create a Durable HTTP starter function
 * - run 'npm install durable-functions' from the wwwroot folder of your 
 *    function app in Kudu
 */

const df = require("durable-functions");

module.exports = df.orchestrator(function* (context) {

    const input = context.df.getInput()
    
    yield context.df.createTimer(new Date(input.startAt))
    
    
    return yield context.df.callActivity('sendEmail', input);
});
github Azure / azure-functions-durable-js / samples / E1_HelloSequence / index.js View on Github external
const df = require("durable-functions");

module.exports = df.orchestrator(function*(context){
    context.log("Starting chain sample");
    const output = [];
    output.push(yield context.df.callActivity("E1_SayHello", "Tokyo"));
    output.push(yield context.df.callActivity("E1_SayHello", "Seattle"));
    output.push(yield context.df.callActivity("E1_SayHello", "London"));

    return output;
});
github Azure / azure-functions-durable-js / samples / cancel-timer / index.js View on Github external
const df = require("durable-functions");
const moment = require('moment');

module.exports = df.orchestrator(function*(context){
    const expiration = moment.utc(context.df.currentUtcDateTime).add(2, 'm');
    const timeoutTask = context.df.createTimer(expiration.toDate());

    const hello = yield context.df.callActivity("E1_SayHello", "from the other side");

    if (!timeoutTask.isCompleted) {
        timeoutTask.cancel();
    }

    return hello;
});
github christiannwamba / calendar-app / serverless / schedule / index.js View on Github external
module.exports = async function (context, req) {
    const client = df.getClient(context);
    const instanceId = await client.startNew(req.params.functionName, undefined, req.body);

    context.log(`Started orchestration with ID = '${instanceId}'.`);

    return client.createCheckStatusResponse(context.bindingData.req, instanceId);
};

durable-functions

Durable Functions library for Node.js Azure Functions

MIT
Latest version published 9 months ago

Package Health Score

81 / 100
Full package analysis