Skip to content

Commit

Permalink
Minor updated in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Aguiar authored and Gavin Aguiar committed May 19, 2023
1 parent 8358cde commit c454ad8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.15.0, 4.0.0)"
"version": "[4.*, 5.0.0)"
}
32 changes: 28 additions & 4 deletions src/Azure.Functions.Cli/StaticResources/templatesv2.json
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@
],
"id": "TimerTrigger-Python",
"files": {
"blueprint.py": "# Register this blueprint by adding the following line of code \r\n# to your entry point file. \r\n# app.register_functions($(BLUEPRINT_FILENAME)) \r\n# \r\n#Please refer to https://aka.ms/azure-functions-python-blueprints\r\n\r\n\r\nimport logging\r\nimport azure.functions as func\r\nfrom azure.functions import Blueprint\r\n\r\n$(BLUEPRINT_FILENAME) = Blueprint()",
"blueprint.py": "# Register this blueprint by adding the following line of code \r\n# to your entry point file. \r\n# app.register_functions($(BLUEPRINT_FILENAME)) \r\n# \r\n#Please refer to https://aka.ms/azure-functions-python-blueprints\r\n\r\n\r\nimport logging\r\nimport azure.functions as func\r\n\r\n$(BLUEPRINT_FILENAME) = func.Blueprint()",
"blueprint_body.py": "\r\n@$(BLUEPRINT_FILENAME).schedule(schedule=\"$(SCHEDULE_INPUT)\", arg_name=\"myTimer\", run_on_startup=True,\r\n use_monitor=False) \r\ndef $(FUNCTION_NAME_INPUT)(myTimer: func.TimerRequest) -> None:\r\n if myTimer.past_due:\r\n logging.info('The timer is past due!')\r\n\r\n logging.info('Python timer trigger function executed')",
"function_app.py": "import datetime\r\nimport logging\r\nimport azure.functions as func\r\n\r\napp = func.FunctionApp()\r\n\r\n@app.schedule(schedule=\"$(SCHEDULE_INPUT)\", arg_name=\"myTimer\", run_on_startup=True,\r\n use_monitor=False) \r\ndef $(FUNCTION_NAME_INPUT)(myTimer: func.TimerRequest) -> None:\r\n utc_timestamp = datetime.datetime.utcnow().replace(\r\n tzinfo=datetime.timezone.utc).isoformat()\r\n\r\n if myTimer.past_due:\r\n logging.info('The timer is past due!')\r\n\r\n logging.info('Python timer trigger function ran at %s', utc_timestamp)",
"function_body.py": "\r\n@app.schedule(schedule=\"$(SCHEDULE_INPUT)\", arg_name=\"myTimer\", run_on_startup=True,\r\n use_monitor=False) \r\ndef $(FUNCTION_NAME_INPUT)(myTimer: func.TimerRequest) -> None:\r\n \r\n if myTimer.past_due:\r\n logging.info('The timer is past due!')\r\n\r\n logging.info('Python timer trigger function executed')",
Expand Down Expand Up @@ -1390,6 +1390,12 @@
"required": true,
"defaultValue": "servicebustopicname"
},
{
"assignTo": "$(SERVICEBUS_SUBSCRIPTION_NAME_INPUT)",
"paramId": "serviceBusTrigger-subscriptionName",
"required": true,
"defaultValue": "servicebussubscriptionName"
},
{
"assignTo": "$(CONNECTION_STRING_INPUT)",
"paramId": "serviceBusTrigger-connection",
Expand Down Expand Up @@ -1419,6 +1425,12 @@
"required": true,
"defaultValue": "servicebustopicname"
},
{
"assignTo": "$(SERVICEBUS_SUBSCRIPTION_NAME_INPUT)",
"paramId": "serviceBusTrigger-subscriptionName",
"required": true,
"defaultValue": "servicebussubscriptionName"
},
{
"assignTo": "$(CONNECTION_STRING_INPUT)",
"paramId": "serviceBusTrigger-connection",
Expand Down Expand Up @@ -1447,6 +1459,12 @@
"required": true,
"defaultValue": "servicebustopicname"
},
{
"assignTo": "$(SERVICEBUS_SUBSCRIPTION_NAME_INPUT)",
"paramId": "serviceBusTrigger-subscriptionName",
"required": true,
"defaultValue": "servicebussubscriptionName"
},
{
"assignTo": "$(CONNECTION_STRING_INPUT)",
"paramId": "serviceBusTrigger-connection",
Expand Down Expand Up @@ -1477,6 +1495,12 @@
"required": true,
"defaultValue": "servicebustopicname"
},
{
"assignTo": "$(SERVICEBUS_SUBSCRIPTION_NAME_INPUT)",
"paramId": "serviceBusTrigger-subscriptionName",
"required": true,
"defaultValue": "servicebussubscriptionName"
},
{
"assignTo": "$(CONNECTION_STRING_INPUT)",
"paramId": "serviceBusTrigger-connection",
Expand Down Expand Up @@ -1561,9 +1585,9 @@
"id": "ServiceBusTopicTrigger-Python",
"files": {
"blueprint.py": "# Register this blueprint by adding the following line of code \r\n# to your entry point file. \r\n# app.register_functions($(BLUEPRINT_FILENAME)) \r\n# \r\n#Please refer to https://aka.ms/azure-functions-python-blueprints\r\n\r\nimport logging\r\nimport azure.functions as func\r\n\r\n\r\n$(BLUEPRINT_FILENAME) = func.Blueprint()",
"blueprint_body.py": "\r\n@$(BLUEPRINT_FILENAME).service_bus_topic_trigger(arg_name=\"azservicebus\", topic_name=\"$(SERVICEBUS_NAME_INPUT)\",\r\n connection=\"$(CONNECTION_STRING_INPUT)\") \r\ndef $(FUNCTION_NAME_INPUT)(azservicebus: func.ServiceBusMessage):\r\n logging.info('Python ServiceBus trigger processed a message: %s',\r\n azservicebus.get_body().decode('utf-8'))\r\n",
"function_app.py": "import azure.functions as func\r\nimport logging\r\n\r\napp = func.FunctionApp()\r\n\r\n@app.service_bus_topic_trigger(arg_name=\"azservicebus\", topic_name=\"$(SERVICEBUS_NAME_INPUT)\",\r\n connection=\"$(CONNECTION_STRING_INPUT)\") \r\ndef $(FUNCTION_NAME_INPUT)(azservicebus: func.ServiceBusMessage):\r\n logging.info('Python ServiceBus trigger processed a message: %s',\r\n azservicebus.get_body().decode('utf-8'))\r\n",
"function_body.py": "\r\n@app.service_bus_topic_trigger(arg_name=\"azservicebus\", topic_name=\"$(SERVICEBUS_NAME_INPUT)\",\r\n connection=\"$(CONNECTION_STRING_INPUT)\") \r\ndef $(FUNCTION_NAME_INPUT)(azservicebus: func.ServiceBusMessage):\r\n logging.info('Python ServiceBus trigger processed a message: %s',\r\n azservicebus.get_body().decode('utf-8'))\r\n",
"blueprint_body.py": "\r\n@$(BLUEPRINT_FILENAME).service_bus_topic_trigger(arg_name=\"azservicebus\", subscription_name=\"$(SERVICEBUS_SUBSCRIPTION_NAME_INPUT)\", topic_name=\"$(SERVICEBUS_NAME_INPUT)\",\r\n connection=\"$(CONNECTION_STRING_INPUT)\") \r\ndef $(FUNCTION_NAME_INPUT)(azservicebus: func.ServiceBusMessage):\r\n logging.info('Python ServiceBus trigger processed a message: %s',\r\n azservicebus.get_body().decode('utf-8'))\r\n",
"function_app.py": "import azure.functions as func\r\nimport logging\r\n\r\napp = func.FunctionApp()\r\n\r\n@app.service_bus_topic_trigger(arg_name=\"azservicebus\", $(SERVICEBUS_SUBSCRIPTION_NAME_INPUT) topic_name=\"$(SERVICEBUS_NAME_INPUT)\",\r\n connection=\"$(CONNECTION_STRING_INPUT)\") \r\ndef $(FUNCTION_NAME_INPUT)(azservicebus: func.ServiceBusMessage):\r\n logging.info('Python ServiceBus trigger processed a message: %s',\r\n azservicebus.get_body().decode('utf-8'))\r\n",
"function_body.py": "\r\n@app.service_bus_topic_trigger(arg_name=\"azservicebus\", subscription_name=\"$(SERVICEBUS_SUBSCRIPTION_NAME_INPUT)\", topic_name=\"$(SERVICEBUS_NAME_INPUT)\",\r\n connection=\"$(CONNECTION_STRING_INPUT)\") \r\ndef $(FUNCTION_NAME_INPUT)(azservicebus: func.ServiceBusMessage):\r\n logging.info('Python ServiceBus trigger processed a message: %s',\r\n azservicebus.get_body().decode('utf-8'))\r\n",
"servicebustopic_trigger_template.md": "# Azure Functions: Service Bus Topic Trigger in Python\r\n\r\n## Service Bus Topic Trigger\r\n\r\nUse the Service Bus Queue trigger to respond to messages from a Service Bus topic. Starting with extension version 3.1.0, you can trigger on a session-enabled topic.\r\n\r\n## Using the Template\r\n\r\nFollowing is an example code snippet for Service Bus Topic Trigger using the [Python programming model V2](https://aka.ms/pythonprogrammingmodel) (currently in Preview).\r\n\r\n```python\r\nimport logging\r\nimport azure.functions as func\r\n\r\napp = func.FunctionApp()\r\n\r\[email protected]_name(name=\"ServiceBusTopicTrigger1\")\r\[email protected]_bus_topic_trigger(arg_name=\"message\", topic_name=\"mytopic\", connection=\"<CONNECTION_SETTING>\", subscription_name=\"testsub\")\r\ndef test_function(message: func.ServiceBusMessage):\r\n message_body = message.get_body().decode(\"utf-8\")\r\n logging.info(\"Python ServiceBus topic trigger processed message.\")\r\n logging.info(\"Message Body: \" + message_body)\r\n```\r\n\r\nTo run the code snippet generated through the command palette, note the following:\r\n\r\n- The function application is defined and named `app`.\r\n- Confirm that the parameters within the trigger reflect values that correspond with your storage account.\r\n- The name of the file must be `function_app.py`.\r\n \r\nNote that Service Bus output bindings are also supported in Azure Functions. To learn more, see [Azure Service Bus bindings for Azure Functions](https://aka.ms/azure-function-binding-service-bus)\r\n\r\n## V2 Programming Model\r\n\r\nThe v2 programming model in Azure Functions Python delivers an experience that aligns with Python development principles, and subsequently with commonly used Python frameworks. \r\n\r\nTo learn more about using the Python programming model for Azure Functions, see the [Azure Functions Python developer guide](https://aka.ms/pythondeveloperguide). Note that in addition to the documentation, [hints](https://aka.ms/functions-python-hints) are available in code editors that support type checking with PYI files."
}
},
Expand Down

0 comments on commit c454ad8

Please sign in to comment.