Skip to content

Commit ff73b42

Browse files
committed
Add asyncio example
1 parent bc84fa2 commit ff73b42

5 files changed

Lines changed: 32 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ select = [
1818

1919
ignore = ["E501"]
2020

21-
[tool.ruff.flake8-annotations]
21+
[tool.ruff.lint.flake8-annotations]
2222
suppress-none-returning = true

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ deltalake~=0.20
22
pandas~=2.2
33
polars~=1.9
44
requests~=2.32
5+
aiohttp~=3.10

v2/function_app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import azure.functions as func
22
from copy_blobs.copy_blobs import copy_blobs_bp
33
from http_trigger.http_trigger import http_bp
4+
from http_trigger_async_exec.http_trigger_async_execution import http_async_exec_bp
45
from simple_blob_trigger.simple_blob_trigger import simple_blob_trigger_bp
56
from simple_blob_trigger_managed_identity.simple_blob_trigger_managed_identity import (
67
simple_blob_trigger_mi_bp,
@@ -14,6 +15,7 @@
1415

1516
app.register_functions(copy_blobs_bp)
1617
app.register_functions(http_bp)
18+
app.register_functions(http_async_exec_bp)
1719
app.register_functions(simple_blob_trigger_bp)
1820
app.register_functions(simple_blob_trigger_mi_bp)
1921
app.register_functions(write_delta_table_bp)

v2/http_trigger_async_exec/__init__.py

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import asyncio
2+
3+
import aiohttp
4+
import azure.functions as func
5+
6+
http_async_exec_bp = func.Blueprint()
7+
8+
9+
@http_async_exec_bp.route(route="http_trigger_async_exec")
10+
def http_trigger_async_execution(req: func.HttpRequest) -> func.HttpResponse:
11+
async def query_current_time(session: aiohttp.ClientSession, tz: str):
12+
async with session.get(
13+
f"http://worldtimeapi.org/api/timezone/{tz}"
14+
) as response:
15+
data = await response.json()
16+
print(
17+
f"In timezone {tz} it is currently {data['datetime'].strftime('%H:%M')}"
18+
)
19+
20+
async def main():
21+
timezones = ["Europe/Berlin", "America/New_York", "Asia/Tokyo"]
22+
async with aiohttp.ClientSession() as s:
23+
async with asyncio.TaskGroup() as tg:
24+
for tz in timezones:
25+
tg.create_task(query_current_time(s, tz))
26+
27+
asyncio.run(main())
28+
return func.HttpResponse(status_code=200)

0 commit comments

Comments
 (0)