Skip to content

Commit 5b33092

Browse files
author
Hanzhang Zeng (Roger)
committed
Merge branch 'dev'
2 parents ff8ee95 + ab828a2 commit 5b33092

File tree

24 files changed

+459
-32
lines changed

24 files changed

+459
-32
lines changed

azure_functions_worker/bindings/datumdef.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
4+
from typing import Any
5+
import json
36
from .. import protos
47

58

@@ -8,6 +11,29 @@ def __init__(self, value, type):
811
self.value = value
912
self.type = type
1013

14+
@property
15+
def python_value(self) -> Any:
16+
if self.value is None or self.type is None:
17+
return None
18+
elif self.type in ('bytes', 'string', 'int', 'double'):
19+
return self.value
20+
elif self.type == 'json':
21+
return json.loads(self.value)
22+
elif self.type == 'collection_string':
23+
return [v for v in self.value.string]
24+
elif self.type == 'collection_bytes':
25+
return [v for v in self.value.bytes]
26+
elif self.type == 'collection_double':
27+
return [v for v in self.value.double]
28+
elif self.type == 'collection_sint64':
29+
return [v for v in self.value.sint64]
30+
else:
31+
return self.value
32+
33+
@property
34+
def python_type(self) -> type:
35+
return type(self.python_value)
36+
1137
def __eq__(self, other):
1238
if not isinstance(other, type(self)):
1339
return False

azure_functions_worker/dispatcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ def on_logging(self, record: logging.LogRecord, formatted_msg: str) -> None:
170170
log_level = getattr(protos.RpcLog, 'None')
171171

172172
if is_system_log_category(record.name):
173-
log_category = protos.RpcLog.RpcLogCategory.System
173+
log_category = protos.RpcLog.RpcLogCategory.Value('System')
174174
else: # customers using logging will yield 'root' in record.name
175-
log_category = protos.RpcLog.RpcLogCategory.User
175+
log_category = protos.RpcLog.RpcLogCategory.Value('User')
176176

177177
log = dict(
178178
level=log_level,

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def run(self):
257257

258258
setup(
259259
name='azure-functions-worker',
260-
version='1.1.3',
260+
version='1.1.4',
261261
description='Python Language Worker for Azure Functions Host',
262262
long_description=long_description,
263263
long_description_content_type='text/markdown',
@@ -286,6 +286,8 @@ def run(self):
286286
extras_require={
287287
'dev': [
288288
'azure-functions==1.3.0',
289+
'azure-eventhub~=5.1.0',
290+
'python-dateutil~=2.8.1',
289291
'flake8~=3.7.9',
290292
'mypy',
291293
'pytest',

tests/endtoend/eventhub_batch_functions/eventhub_multiple/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import json
44

55

6+
# This is an actual EventHub trigger which handles Eventhub events in batches.
7+
# It serializes multiple event data into a json and store it into a blob.
68
def main(events):
79
table_entries = []
810
for event in events:

tests/endtoend/eventhub_batch_functions/eventhub_output_batch/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import azure.functions as func
44

55

6+
# An HttpTrigger to generating EventHub event from EventHub Output Binding
67
def main(req: func.HttpRequest) -> str:
78
events = req.get_body().decode('utf-8')
89
return events

tests/endtoend/eventhub_batch_functions/get_eventhub_batch_triggered/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
import azure.functions as func
44

55

6+
# Retrieve the event data from storage blob and return it as Http response
67
def main(req: func.HttpRequest, testEntities):
78
return func.HttpResponse(status_code=200, body=testEntities)
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
{
2-
"scriptFile": "__init__.py",
3-
"bindings": [
4-
{
5-
"type": "httpTrigger",
6-
"direction": "in",
7-
"authLevel": "anonymous",
8-
"methods": [
9-
"get"
10-
],
11-
"name": "req"
12-
},
13-
{
14-
"direction": "in",
15-
"type": "table",
16-
"name": "testEntities",
17-
"partitionKey": "WillBePopulated",
18-
"tableName": "EventHubBatchTest",
19-
"connection": "AzureWebJobsStorage"
20-
},
21-
{
22-
"type": "http",
23-
"direction": "out",
24-
"name": "$return"
25-
}
26-
]
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"type": "httpTrigger",
6+
"direction": "in",
7+
"authLevel": "anonymous",
8+
"methods": [
9+
"get"
10+
],
11+
"name": "req"
12+
},
13+
{
14+
"direction": "in",
15+
"type": "table",
16+
"name": "testEntities",
17+
"partitionKey": "WillBePopulated",
18+
"tableName": "EventHubBatchTest",
19+
"connection": "AzureWebJobsStorage"
20+
},
21+
{
22+
"type": "http",
23+
"direction": "out",
24+
"name": "$return"
25+
}
26+
]
2727
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import azure.functions as func
4+
5+
6+
# Retrieve the event data from storage blob and return it as Http response
7+
def main(req: func.HttpRequest, file: func.InputStream) -> str:
8+
return func.HttpResponse(body=file.read().decode('utf-8'),
9+
status_code=200,
10+
mimetype='application/json')
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"type": "httpTrigger",
6+
"direction": "in",
7+
"name": "req"
8+
},
9+
{
10+
"type": "blob",
11+
"direction": "in",
12+
"name": "file",
13+
"connection": "AzureWebJobsStorage",
14+
"path": "python-worker-tests/test-metadata-batch-triggered.txt"
15+
},
16+
{
17+
"type": "http",
18+
"direction": "out",
19+
"name": "$return"
20+
}
21+
]
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import typing
5+
import json
6+
import azure.functions as func
7+
8+
9+
# This is an actual EventHub trigger which handles Eventhub events in batches.
10+
# It serializes multiple event data into a json and store it into a blob.
11+
def main(events: typing.List[func.EventHubEvent]) -> bytes:
12+
event_list = []
13+
for event in events:
14+
event_dict: typing.Mapping[str, typing.Any] = {
15+
'body': event.get_body().decode('utf-8'),
16+
'enqueued_time': event.enqueued_time.isoformat(),
17+
'partition_key': event.partition_key,
18+
'sequence_number': event.sequence_number,
19+
'offset': event.offset,
20+
'metadata': event.metadata
21+
}
22+
event_list.append(event_dict)
23+
24+
return json.dumps(event_list)

0 commit comments

Comments
 (0)