-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_app.py
More file actions
71 lines (58 loc) · 2.03 KB
/
Copy pathfunction_app.py
File metadata and controls
71 lines (58 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import azure.functions as func
import logging
from repositories.table_storage_repository import TableDirectoryClient
from logger_config import setup_logging
import logging
setup_logging()
logger = logging.getLogger(__name__)
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="medium_http_trigger")
def medium_http_trigger(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
table_name = "ActivityLogs"
table_client = TableDirectoryClient(table_name)
single_entity = {
"PartitionKey": "TestPartition",
"RowKey": "1",
"UserId": "3",
"Action": "SingleInsertTest",
"Timestamp": "2024-11-24T12:00:00Z"
}
try:
print("Testing single entity insertion...")
table_client.insert_entity(single_entity)
print("Single entity inserted successfully!")
except Exception as e:
print(f"Error inserting single entity: {str(e)}")
multiple_entities = [
{
"PartitionKey": "TestPartition",
"RowKey": "2",
"UserId": "3",
"Action": "BulkInsertTest1",
"Timestamp": "2024-11-24T12:05:00Z"
},
{
"PartitionKey": "TestPartition",
"RowKey": "3",
"UserId": "3",
"Action": "BulkInsertTest2",
"Timestamp": "2024-11-24T12:10:00Z"
},
]
try:
print("Testing multiple entities insertion...")
table_client.insert_entities(multiple_entities)
print("Multiple entities inserted successfully!")
except Exception as e:
print(f"Error inserting multiple entities: {str(e)}")
entities = table_client.read_entities()
if entities:
for entity in entities:
logging.info(f"Entidade: {entity}")
else:
logging.info("No entities found or an error occurred.")
return func.HttpResponse(
"Entities read successfully! Check logs for more details.",
status_code=200
)