0
votes

We are switching over our Azure WebJobs to Azure Functions (for multiple reasons besides this post). But we internally can't really agree on the architecture for those functions.

Currently we have one WebJob that does a single tasks from A-Z.
E.g. Status emails: (Gets triggered from the scheduler)
1. Looks up all recepients
2. Send email to all of those
3. Logs success/failure for each individual recepient
4. Logs success/failure for the whole run

And we have multiple web-jobs that do similar tasks.

Now we have 3 ways we can implement this in the future.

  1. One-to-one conversion. Move the complete WebJob functionality into one Azure function
  2. Split the above process into 4 different Azure functions. E.g. one that looks up the recipients and then calls another function that sends out the email and so on.
  3. Combine all WebJobs into one Azure function

Personally, I would tend towards solution 3. But some team members tend towards 1. What do you think?

1

1 Answers

1
votes

I would go with option 3 too. You can use Durable Functions and let it control the workflow, and create activities for each step (1-4).

[FunctionName("Chaining")]
public static async Task<object> Run(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
{
    try
    {
        var recipients = await context.CallActivityAsync<object>("GetAllRecipients", null);
        foreach(var recipient in recipients)
        {
            //maybe return a complex object with more info about the failure
            var success = await context.CallActivityAsync<object>("SendEmail", recipient); 
            if (! success)
            {
                await context.CallActivityAsync<object>("LogError", recipient);
            }
        }

        return  await context.CallActivityAsync<object>("NotifyCompletion", null);
    }
    catch (Exception ex)
    {
        // Error handling or compensation goes here.
        await context.CallActivityAsync<object>("LogError", ex);
    }
}

more info: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview