-
Notifications
You must be signed in to change notification settings - Fork 70
feat: support durabletask-azurefunctions #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
| using_legacy = True | ||
| _logger.warning("`azure-functions-durable` is deprecated. " \ | ||
| "Please migrate to the new `durabletask-azurefunctions` package. " \ | ||
| "See <AKA.MS LINK HERE> for more details.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Log a warning if azure-functions-durable is being used.
|
|
||
| if using_durable_task and using_legacy: | ||
| # Both packages are installed; prefer `durabletask-azurefunctions`. | ||
| _logger.warning("Both `azure-functions-durable` and " \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case that the customer has both durable packages, log a warning & prioritize durabletask-azurefunctions.
| raise Exception(error_message) | ||
| _logger.info("Getting Durable Functions blueprint.") | ||
| df = get_durable_package() | ||
| df_bp = df.Blueprint() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
df here will now be either azure-functions-durable or durabletask-azurefunctions
| class LegacyOrchestrationTriggerConverter(meta.InConverter, | ||
| meta.OutConverter, | ||
| binding='orchestrationTrigger', | ||
| binding=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous converters are renamed to "Legacy" with no changes. binding is set to None so that they are not automatically registered
|
|
||
| # ---------------- Durable Task Durable Functions Converters ---------------- # | ||
| # Durable Function Orchestration Trigger | ||
| class OrchestrationTriggerConverter(meta.InConverter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, converters for durable task package are named OrchestrationTrigger Converter, EntityTriggerConverter, ActivityTriggerConverter, and DurableClientConverter - open to renaming if preferable
| def encode(cls, obj: typing.Any, *, | ||
| expected_type: typing.Optional[type]) -> meta.Datum: | ||
| # Durable function context should be a string | ||
| return meta.Datum(type='string', value=obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New converters for durable task are currently identical to legacy converters except for this change based on microsoft/durabletask-python#75 (comment).
Will update these converters as needed to be compatible with durable task
| _logger.info("Durable Functions package loaded: %s", pkg.__name__) | ||
| _logger.info("Current bindings before registration: %s", meta._ConverterMeta._bindings) | ||
| # Clear existing bindings if they exist | ||
| meta._ConverterMeta._bindings.pop("orchestrationTrigger", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never happen, but just in case - if there are bindings already registered for durable, remove them. Then we add the appropriate converter (Legacy vs. new) based on the durable package brought by the customer
| "Attempted to use a Durable Functions decorator, " \ | ||
| "but the `azure-functions-durable` SDK package could not be " \ | ||
| "found. Please install `azure-functions-durable` to use " \ | ||
| "but the `durabletask-azurefunctions` SDK package could not be " \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the case where the customer tries to use a DF decorator (func.FunctionApp) but doesn't have either package installed. df is None, so we raise an error
| # Licensed under the MIT License. | ||
| import logging | ||
|
|
||
| _logger = logging.getLogger('azure.functions.AsgiMiddleware') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the info logs will be removed in the future, just for debugging purposes now
| # Licensed under the MIT License. | ||
| import logging | ||
|
|
||
| _logger = logging.getLogger('azure.functions.AsgiMiddleware') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why AsgiMiddleware is used in durable for logging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary, will be updated later
| If neither package is installed, we return None. | ||
| """ | ||
| _logger.info("Attempting to import Durable Functions package.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this log debug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These logs are just for debugging, will be removed / moved to debug later
| "Please migrate to the new `durabletask-azurefunctions` package. " \ | ||
| "See <AKA.MS LINK HERE> for more details.") | ||
| except ImportError: | ||
| _logger.info("`azure-functions-durable` package not found.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a debug too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These logs are just for debugging, will be removed / moved to debug later
| _logger.info("`azure-functions-durable` package not found.") | ||
| pass | ||
| try: | ||
| import durabletask.azurefunctions as durable_functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to check for both? If durabletask is added, lets directly use it and just add a log that durable task is being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to maintain backwards compatibility with azure-functions-durable. We have to check for both to determine which converter / decorator is being used. This check is only done once though - after that, the df variable will save which module is being used
| "Durable Functions." | ||
| raise Exception(error_message) | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT; extra line added
| from . import mysql # NoQA | ||
|
|
||
|
|
||
| register_durable_converters() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes inside the all block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
register_durable_converters is not exposed to the worker. It's called at init, whenever azure-functions is imported by the worker.
Adding support for durabletask-azurefunctions.