Hello Matthew Hughes,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
Problem
Based on the provided information, I understand that within a Function App named GracePremiumFunctions, multiple timer-triggered functions (GraceWeekly_PC and GraceWeekly1400) are exhibiting unexpected behavior after changes to their CRON expressions. These behaviors include:
Changes to the CRON expressions triggering both functions.
Addition of a third function (testtimer) causing all functions to initiate unexpectedly.
Duplication of transaction logs in Application Insights.
Solution
To solve the problems and address the questions regarding the unexpected behavior of timer-triggered functions within the Function App, you will have to follow these steps:
- Double-check the CRON expressions defined for each timer-triggered function in the function app's configuration. Ensure that each CRON expression is correctly formatted and represents the intended schedule for the respective function.
- Review the function app's configuration to ensure that each function is properly associated with its designated trigger (i.e., the correct CRON expression). Verify that there are no overlapping triggers or conflicting configurations that could cause unintended function invocations.
- After you have done with the above. Consider separating the implementation of each function into its own script file. Create separate Python files for each function (e.g., GraceWeekly_PC.py, GraceWeekly1400.py, TestTimer.py) and specify the corresponding script file names in the function app's configuration. This is how you can separate the implementation of each function into its own Python script file:
- GraceWeekly_PC.py:
import logging import datetime import azure.functions as func def main(planningcentertimer: func.TimerRequest) -> None: utc_timestamp = datetime.datetime.utcnow().replace( tzinfo=datetime.timezone.utc).isoformat() if planningcentertimer.past_due: logging.info('The timer is past due!') logging.info('GraceWeekly_PC timer trigger function ran at %s', utc_timestamp)
- GraceWeekly1400.py:
import logging import datetime import azure.functions as func def main(churchmetricstimer: func.TimerRequest) -> None: utc_timestamp = datetime.datetime.utcnow().replace( tzinfo=datetime.timezone.utc).isoformat() if churchmetricstimer.past_due: logging.info('The timer is past due!') logging.info('GraceWeekly1400 timer trigger function ran at %s', utc_timestamp)
- TestTimer.py:
Ensure that the scriptFile configuration in the function app'simport logging import datetime import azure.functions as func def main(testtimer: func.TimerRequest) -> None: utc_timestamp = datetime.datetime.utcnow().replace( tzinfo=datetime.timezone.utc).isoformat() if testtimer.past_due: logging.info('The timer is past due!') logging.info('TestTimer timer trigger function ran at %s', utc_timestamp)
function.json
file points to the respective script file for each function.
- GraceWeekly_PC.py:
- Then, utilize dependency injection to ensure that each function's dependencies are correctly scoped and isolated. Inject any shared dependencies required by multiple functions to avoid conflicts or unintended interactions.
- So, after all perform routing to test, debugging, monitor and review Application Insights configuration.
Finally
By following these steps and organizing the functions into separate script files, you can mitigate the issues related to CRON expression changes triggering multiple functions, unexpected function invocations, and duplication of transaction logs. Additionally, thorough testing and monitoring will help ensure the stability and reliability of the Function App. If issues persist, use logging statements within the function code to debug and trace the execution flow.
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam