Hello @QiLi-8593 Thanks for reaching out and posting on the MS Q&A! You might have to refactor the code above and consider running it on Azure Durable Functions instead. Here's my feedback:
-
get_ga_service()
function includes code for parsing command line arguments. Since you'll be running this function on Azure and the goal of the function is to return GA service object, do you really need the part that parses command line arguments? - The client secret is stored inside a
client_secrets.json
file that resides on the same filesystem alongside your Python function files and is referenced as a relative path. This has at least a couple of caveats: (a) referencing a file relatively can be error-prone and requires your Python app file to have read permission to the file. (b) Storing a secret in a flat file is risky and goes against best practices for security. Azure Functions offers integration with KeyVault for handling secrets but there are other options such as storing the secret via App Setting etc. - Same file handling concerns (of pathing & permissions) for writing to the
analytics.dat
file via Storage object. - The overall operation of the
get_ga_service()
function entails reading and writing to files on the same filesystem (i/o operation) as well as authenticating to GA service via HTTP (networking operation). These types of tasks are regarded as stateful workflow because such operations can fail. The operating system could crash and fail the reading/writing of files. HTTP calls to GA could fail due to networking issues. Because of those reasons, Azure Durable Functions is recommended service that is designed to handle such workflow and is highly recommended for your use case. The Azure Functions is designed for stateless tasks.
I've made the suggestions above only based on the code that you provided. Since I'm unaware of the rest of the code, the structure of your functions, the exact error you may be hitting, how you're handling the deployment, and the configuration of your overall Function App, I'm sorry in advance if I misunderstood anything.
However, if any of the feedback shared seems helpful and you'd like to learn more, let me know in the comments and I'd be happy to provide more info and resources.