Skip to content

Commit 0d21579

Browse files
committed
add warmup context
1 parent 132b8da commit 0d21579

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

azure/functions/_abc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def message(self) -> str:
4747
pass
4848

4949

50+
class WarmUpContext(abc.ABC):
51+
"""Warmup context object."""
52+
pass
53+
54+
5055
class TraceContext(abc.ABC):
5156
"""Trace context object."""
5257

@@ -126,6 +131,12 @@ def retry_context(self) -> RetryContext:
126131
"""Context for retries to the function."""
127132
pass
128133

134+
@property
135+
@abc.abstractmethod
136+
def warmup_context(self) -> WarmUpContext:
137+
"""Context for warmup to the function."""
138+
pass
139+
129140

130141
class HttpRequest(abc.ABC):
131142
"""HTTP request object."""

tests/test_http_asgi.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import unittest
66

77
import azure.functions as func
8-
from azure.functions._abc import TraceContext, RetryContext
8+
from azure.functions._abc import TraceContext, RetryContext, WarmUpContext
99
from azure.functions._http_asgi import (
1010
AsgiMiddleware
1111
)
@@ -114,15 +114,17 @@ def _generate_func_context(
114114
function_name='httptrigger',
115115
function_directory='/home/roger/wwwroot/httptrigger',
116116
trace_context=TraceContext,
117-
retry_context=RetryContext
117+
retry_context=RetryContext,
118+
warmup_context=WarmUpContext
118119
) -> func.Context:
119120
class MockContext(func.Context):
120-
def __init__(self, ii, fn, fd, tc, rc):
121+
def __init__(self, ii, fn, fd, tc, rc, wc):
121122
self._invocation_id = ii
122123
self._function_name = fn
123124
self._function_directory = fd
124125
self._trace_context = tc
125126
self._retry_context = rc
127+
self._warmup_context = wc
126128

127129
@property
128130
def invocation_id(self):
@@ -144,8 +146,12 @@ def trace_context(self):
144146
def retry_context(self):
145147
return self._retry_context
146148

149+
@property
150+
def warmup_context(self):
151+
return self._warmup_context
152+
147153
return MockContext(invocation_id, function_name, function_directory,
148-
trace_context, retry_context)
154+
trace_context, retry_context, warmup_context)
149155

150156
def test_middleware_calls_app(self):
151157
app = MockAsgiApplication()

tests/test_http_wsgi.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from io import StringIO, BytesIO
66

77
import azure.functions as func
8-
from azure.functions._abc import TraceContext, RetryContext
8+
from azure.functions._abc import TraceContext, RetryContext, WarmUpContext
99
from azure.functions._http import HttpResponseHeaders
1010
from azure.functions._http_wsgi import (
1111
WsgiRequest,
@@ -223,15 +223,17 @@ def _generate_func_context(
223223
function_name='httptrigger',
224224
function_directory='/home/roger/wwwroot/httptrigger',
225225
trace_context=TraceContext,
226-
retry_context=RetryContext
226+
retry_context=RetryContext,
227+
warmup_context=WarmUpContext
227228
) -> func.Context:
228229
class MockContext(func.Context):
229-
def __init__(self, ii, fn, fd, tc, rc):
230+
def __init__(self, ii, fn, fd, tc, rc, wc):
230231
self._invocation_id = ii
231232
self._function_name = fn
232233
self._function_directory = fd
233234
self._trace_context = tc
234235
self._retry_context = rc
236+
self._warmup_context = wc
235237

236238
@property
237239
def invocation_id(self):
@@ -253,8 +255,12 @@ def trace_context(self):
253255
def retry_context(self):
254256
return self._retry_context
255257

258+
@property
259+
def warmup_context(self):
260+
return self._warmup_context
261+
256262
return MockContext(invocation_id, function_name, function_directory,
257-
trace_context, retry_context)
263+
trace_context, retry_context, warmup_context)
258264

259265
def _generate_wsgi_app(self,
260266
status='200 OK',

0 commit comments

Comments
 (0)