1
votes

We have hosted an azure application and enabled for multiple organizations by creating a separate DB per Org. Now, we need to run a background service that needs to generate:

  1. Configure Azure function with TimerTrigger Enabled (Time of Run will be configured by each organization in the Admin application)

  2. The Azure function should be invoked as many times based on the time configured by the organization(same function will be called multiple instances)

  3. The function schedule time for each org should be updated on demand (through c# code) - I am not sure if this can be done

  4. Based on the time and org details, function needs to fetch records from respective DB and process it.

  5. To minimize the Function timeout issue - Records will be processed as batch and get updated in the respective Org DB.

Let know your inputs on this

Thank you!

1
It will work dont know if it is the best option for you.Thomas

1 Answers

1
votes

Functions are not intended to be run for long time. If you have many tenants and/or report generation is slow, a function invocation can be killed (after 5 minutes by default).

If you need to run a long job by timer, Web Jobs are better match.

If I were to use Functions, I would do it slightly differently:

  1. Timer-triggered Function runs every day (or whatever the frequency is) and sends 1 message per tenant to a queue saying "please generate the report for tenant X". It will run pretty fast.

  2. Another Queue-triggered Function listens to that queue, gets the messages and generates just one report per message for tenant X.

This way you will distribute the work more evenly, and also isolate possible failures and potentially generate multiple reports in parallel.

You might also want to have a look at Durable Functions where you could implement a similar workflow: activity function to generate a single report, and orchestrator function to call it for each tenant.