Skip to content

Commit 194961c

Browse files
committed
8timer
1 parent f5e00ea commit 194961c

18 files changed

+353
-1
lines changed

Diff for: .vscode/extensions.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions",
4+
"ms-python.python"
5+
]
6+
}

Diff for: .vscode/launch.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Attach to Python Functions",
6+
"type": "python",
7+
"request": "attach",
8+
"port": 9091,
9+
"preLaunchTask": "func: host start"
10+
}
11+
]
12+
}

Diff for: .vscode/settings.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"azureFunctions.deploySubpath": "8test",
3+
"azureFunctions.scmDoBuildDuringDeployment": true,
4+
"azureFunctions.pythonVenv": ".venv",
5+
"azureFunctions.projectLanguage": "Python",
6+
"azureFunctions.projectRuntime": "~4",
7+
"debug.internalConsoleOptions": "neverOpen",
8+
"azureFunctions.projectLanguageModel": 2
9+
}

Diff for: .vscode/tasks.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "func",
6+
"label": "func: host start",
7+
"command": "host start",
8+
"problemMatcher": "$func-python-watch",
9+
"isBackground": true,
10+
"dependsOn": "pip install (functions)",
11+
"options": {
12+
"cwd": "${workspaceFolder}/8test"
13+
}
14+
},
15+
{
16+
"label": "pip install (functions)",
17+
"type": "shell",
18+
"osx": {
19+
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
20+
},
21+
"windows": {
22+
"command": "${config:azureFunctions.pythonVenv}/Scripts/python -m pip install -r requirements.txt"
23+
},
24+
"linux": {
25+
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
26+
},
27+
"problemMatcher": [],
28+
"options": {
29+
"cwd": "${workspaceFolder}/8test"
30+
}
31+
}
32+
]
33+
}

Diff for: 6identity/.funcignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Diff for: 6identity/.gitignore

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
bin
2+
obj
3+
csx
4+
.vs
5+
edge
6+
Publish
7+
8+
*.user
9+
*.suo
10+
*.cscfg
11+
*.Cache
12+
project.lock.json
13+
14+
/packages
15+
/TestResults
16+
17+
/tools/NuGet.exe
18+
/App_Data
19+
/secrets
20+
/data
21+
.secrets
22+
appsettings.json
23+
local.settings.json
24+
25+
node_modules
26+
dist
27+
28+
# Local python packages
29+
.python_packages/
30+
31+
# Python Environments
32+
.env
33+
.venv
34+
env/
35+
venv/
36+
ENV/
37+
env.bak/
38+
venv.bak/
39+
40+
# Byte-compiled / optimized / DLL files
41+
__pycache__/
42+
*.py[cod]
43+
*$py.class
44+
45+
# Azurite artifacts
46+
__blobstorage__
47+
__queuestorage__
48+
__azurite_db*__.json

Diff for: 6identity/.vscode/extensions.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions"
4+
]
5+
}

Diff for: 6identity/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# functionspy
2+
3+
## 6 Identity
4+
This sample follows [2 Function storage](../2functionstorage/) and extends it with an input binding from a storage account queue.
5+
6+
7+
region=northeurope
8+
resourcegroup=functionspy6
9+
storageaccount=functionspy6sa
10+
pythonversion=3.11
11+
functionapp=functionspy6fa
12+
az group create --name $resourcegroup --location $region
13+
<!-- az storage account create --name $storageaccount --location $region --resource-group $resourcegroup
14+
az functionapp create --resource-group $resourcegroup --consumption-plan-location westeurope --runtime python --runtime-version $pythonversion --functions-version 4 --name $functionapp --os-type linux --storage-account $storageaccount
15+
func azure functionapp publish $functionapp -->
16+
17+
server=functionspy6sv
18+
database=functionspy6db
19+
20+
az sql server create --name $server --resource-group $resourcegroup --location $region --enable-ad-only-auth --external-admin-principal-type User --external-admin-name pidebrui --external-admin-sid 0a5c2d73-9bb3-47a8-8a81-f580b1a570d0
21+
22+
az sql db create -g $resourcegroup -s $server -n $database --compute-model Serverless -e GeneralPurpose -f Gen5 -c 2
23+
--min-capacity 0.5
24+
--auto-pause-delay 720

Diff for: 6identity/function_app.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import azure.functions as func
2+
import datetime
3+
import json
4+
import logging
5+
6+
app = func.FunctionApp()
7+
8+
# @app.route(route="put_message")
9+
# @app.service_bus_queue_output(arg_name="msg",
10+
# connection="NAMESPACE_CONNECTION_STR",
11+
# queue_name="servicebusqueuename")
12+
# def HttpExample(req: func.HttpRequest, msg: func.Out [str]) -> func.HttpResponse:
13+
# logging.info('Python HTTP trigger function processed a request.')
14+
15+
# name = req.params.get('name')
16+
# if not name:
17+
# try:
18+
# req_body = req.get_json()
19+
# except ValueError:
20+
# pass
21+
# else:
22+
# name = req_body.get('name')
23+
24+
# if name:
25+
# # msg.set("test")
26+
# return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
27+
# else:
28+
# return func.HttpResponse(
29+
# "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
30+
# status_code=200
31+
# )
32+
33+
@app.service_bus_queue_trigger(arg_name="msg", queue_name="servicebusqueuename", connection="NAMESPACE_CONNECTION_STR")
34+
def ServicebusExample(msg: func.ServiceBusMessage):
35+
logging.info('Python ServiceBus Queue trigger processed a message: %s', msg.get_body().decode('utf-8'))

Diff for: 6identity/host.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "2.0",
3+
"logging": {
4+
"applicationInsights": {
5+
"samplingSettings": {
6+
"isEnabled": true,
7+
"excludedTypes": "Request"
8+
}
9+
}
10+
},
11+
"extensionBundle": {
12+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
13+
"version": "[4.*, 5.0.0)"
14+
}
15+
}

Diff for: 6identity/requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Do not include azure-functions-worker in this file
2+
# The Python Worker is managed by the Azure Functions platform
3+
# Manually managing azure-functions-worker may cause unexpected issues
4+
5+
azure-functions

Diff for: 8timer/.gitignore

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
bin
2+
obj
3+
csx
4+
.vs
5+
edge
6+
Publish
7+
8+
*.user
9+
*.suo
10+
*.cscfg
11+
*.Cache
12+
project.lock.json
13+
14+
/packages
15+
/TestResults
16+
17+
/tools/NuGet.exe
18+
/App_Data
19+
/secrets
20+
/data
21+
.secrets
22+
appsettings.json
23+
local.settings.json
24+
25+
node_modules
26+
dist
27+
28+
# Local python packages
29+
.python_packages/
30+
31+
# Python Environments
32+
.env
33+
.venv
34+
env/
35+
venv/
36+
ENV/
37+
env.bak/
38+
venv.bak/
39+
40+
# Byte-compiled / optimized / DLL files
41+
__pycache__/
42+
*.py[cod]
43+
*$py.class
44+
45+
# Azurite artifacts
46+
__blobstorage__
47+
__queuestorage__
48+
__azurite_db*__.json

Diff for: 8timer/.vscode/extensions.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"ms-azuretools.vscode-azurefunctions"
4+
]
5+
}

Diff for: 8timer/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# functionspy
2+
3+
## 8 Timer
4+
This sample shows an Azure Function in Python with timer trigger.
5+
6+
```
7+
func init --python
8+
func new
9+
```
10+
* Timer Trigger
11+
* timer_trigger
12+
* [0 */5 * * * *]
13+
14+
### Run locally
15+
```
16+
func start
17+
```
18+
Log:
19+
Found Python version 3.11.5 (python3).
20+
21+
Azure Functions Core Tools
22+
Core Tools Version: 4.0.5530 Commit hash: N/A +c8883e7f3c06e2b424fbac033806c19d8d91418c (64-bit)
23+
Function Runtime Version: 4.28.5.21962
24+
25+
[2024-06-13T11:38:56.186Z] Customer packages not in sys path.
26+
[2024-06-13T11:38:57.133Z] Worker process started and initialized.
27+
28+
Functions:
29+
30+
timer_trigger: timerTrigger
31+
32+
For detailed output, run func with --verbose flag.
33+
[2024-06-13T11:39:02.036Z] Host lock lease acquired by instance ID '000000000000000000000000C7C8539E'.
34+
[2024-06-13T11:40:00.072Z] Executing 'Functions.timer_trigger' (Reason='Timer fired at 2024-06-13T13:40:00.0307363+02:00', Id=7dc1b3a8-de25-4092-aa34-f72915d0dcb8)
35+
[2024-06-13T11:40:00.141Z] Python timer trigger function executed.
36+
[2024-06-13T11:40:00.164Z] Executed 'Functions.timer_trigger' (Succeeded, Id=7dc1b3a8-de25-4092-aa34-f72915d0dcb8, Duration=119ms)
37+
38+
### Run in Azure
39+
40+
```
41+
region=northeurope
42+
resourcegroup=functionspy8
43+
storageaccount=functionspy8sa
44+
pythonversion=3.11
45+
functionapp=functionspy8fa
46+
az group create --name $resourcegroup --location $region
47+
az storage account create --name $storageaccount --location $region --resource-group $resourcegroup
48+
az functionapp create --resource-group $resourcegroup --consumption-plan-location westeurope --runtime python --runtime-version $pythonversion --functions-version 4 --name $functionapp --os-type linux --storage-account $storageaccount
49+
func azure functionapp publish $functionapp
50+
```
51+
Log:
52+
13/06/2024, 11:50:00,002
53+
Information
54+
Executing 'Functions.timer_trigger' (Reason='Timer fired at 2024-06-13T11:50:00.0012937+00:00', Id=c94f7941-81a1-45c5-8dbd-8525da27126c)
55+
13/06/2024, 11:50:00,028
56+
Information
57+
Python timer trigger function executed.
58+
13/06/2024, 11:50:00,037
59+
Information
60+
Executed 'Functions.timer_trigger' (Succeeded, Id=c94f7941-81a1-45c5-8dbd-8525da27126c, Duration=36ms)
61+
62+
[Source](https://learn.microsoft.com/azure/azure-functions/create-first-function-cli-python)
63+
64+
[Home](../README.md)

Diff for: 8timer/function_app.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import azure.functions as func
2+
import datetime
3+
import json
4+
import logging
5+
6+
app = func.FunctionApp()
7+
8+
@app.timer_trigger(schedule="0 */5 * * * *", arg_name="myTimer", run_on_startup=False,
9+
use_monitor=False)
10+
def timer_trigger(myTimer: func.TimerRequest) -> None:
11+
12+
if myTimer.past_due:
13+
logging.info('The timer is past due!')
14+
15+
logging.info('Python timer trigger function executed.')

Diff for: 8timer/host.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "2.0",
3+
"logging": {
4+
"applicationInsights": {
5+
"samplingSettings": {
6+
"isEnabled": true,
7+
"excludedTypes": "Request"
8+
}
9+
}
10+
},
11+
"extensionBundle": {
12+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
13+
"version": "[4.*, 5.0.0)"
14+
}
15+
}

Diff for: 8timer/requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Do not include azure-functions-worker in this file
2+
# The Python Worker is managed by the Azure Functions platform
3+
# Manually managing azure-functions-worker may cause unexpected issues
4+
5+
azure-functions

Diff for: README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ This is a repository to collect various samples of Azure Functions in Python.
66
## Contents
77
[1 Function](./1function/)
88

9-
[2 Function and storage](./2functionstorage/)
9+
[2 Function to storage](./2functionstorage/)
1010

11+
[3 Storage to Function](./3storagefunction/)
12+
13+
[4 Continuous integration and deployment](./4cicd/)
14+
15+
[5 Azure developer command-line interface](./5azd/)
16+
17+
[6 Identity](./6identity/)

0 commit comments

Comments
 (0)