Skip to content

Commit 62a772f

Browse files
committed
fix
Signed-off-by: laminar <[email protected]>
1 parent 8057745 commit 62a772f

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/functions_framework/context/function_context.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class FunctionContext(object):
1919

2020
def __init__(self, name="", version="", dapr_triggers=None, http_trigger=None,
2121
inputs=None, outputs=None, states=None,
22-
pre_hooks=None, post_hooks=None, tracing=None, port=8080):
22+
pre_hooks=None, post_hooks=None, tracing=None, port=0):
2323
self.name = name
2424
self.version = version
2525
self.dapr_triggers = dapr_triggers
@@ -44,6 +44,7 @@ def from_json(json_dct):
4444
pre_hooks = json_dct.get('pre_hooks', [])
4545
post_hooks = json_dct.get('post_hooks', [])
4646
tracing = json_dct.get('tracing', {})
47+
port = json_dct.get('port', 0)
4748

4849
inputs = None
4950
if inputs_list:
@@ -59,14 +60,15 @@ def from_json(json_dct):
5960
output = Component.from_json(v)
6061
outputs[k] = output
6162

62-
dapr_triggers = [DaprTrigger]
63+
dapr_triggers = []
6364
for trigger in _dapr_triggers:
6465
dapr_triggers.append(DaprTrigger.from_json(trigger))
6566

66-
http_trigger = HTTPRoute.from_json(http_trigger)
67+
if http_trigger:
68+
http_trigger = HTTPRoute.from_json(http_trigger)
6769

6870
return FunctionContext(name, version, dapr_triggers, http_trigger,
69-
inputs, outputs, states, pre_hooks, post_hooks, tracing)
71+
inputs, outputs, states, pre_hooks, post_hooks, tracing, port)
7072

7173

7274
class Component(object):

src/functions_framework/context/runtime_context.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from functions_framework.context.function_context import Component, FunctionContext
14+
from functions_framework.context.function_context import (
15+
Component,
16+
DaprTrigger,
17+
FunctionContext,
18+
HTTPRoute,
19+
)
1520

1621

1722
class RuntimeContext:
@@ -29,14 +34,14 @@ def has_http_trigger(self):
2934
"""Check if the function has http trigger."""
3035
return self.context and self.context.http_trigger
3136

32-
def get_dapr_triggers(self):
37+
def get_dapr_triggers(self) -> [DaprTrigger]:
3338
"""Get dapr trigger."""
3439
if self.context:
3540
return self.context.dapr_triggers
3641
else:
3742
return []
3843

39-
def get_http_trigger(self):
44+
def get_http_trigger(self) -> HTTPRoute:
4045
"""Get http trigger."""
4146
if self.context:
4247
return self.context.http_trigger
@@ -47,4 +52,4 @@ def get_outputs(self) -> [Component]:
4752
if self.context and self.context.outputs:
4853
return self.context.outputs
4954
else:
50-
return [Component]
55+
return []

src/functions_framework/triggers/dapr_trigger/dapr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from cloudevents.sdk.event import v1
1919
from dapr.ext.grpc import App, BindingRequest
2020

21+
from functions_framework import constants
2122
from functions_framework.context.function_context import DaprTrigger
2223
from functions_framework.context.runtime_context import RuntimeContext
2324
from functions_framework.context.user_context import UserContext
@@ -31,6 +32,8 @@ def __init__(self, port, triggers: [DaprTrigger] = None, user_function=None):
3132
self.triggers = triggers
3233
self.app = App()
3334
self.user_function = user_function
35+
if self.port == 0:
36+
self.port = constants.DEFAULT_DAPR_APP_PORT
3437

3538
def start(self, context: RuntimeContext, logger=None):
3639
if not self.triggers:

src/functions_framework/triggers/http_trigger/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, port, trigger: HTTPRoute, source=None, target=None, user_func
3232
self.route_rules = trigger.rules
3333
self.user_function = user_function
3434
self.debug = debug
35-
if self.port is None:
35+
if self.port == 0:
3636
self.port = constants.DEFAULT_HTTP_APP_PORT
3737

3838
def start(self, context: RuntimeContext, logger=None):

0 commit comments

Comments
 (0)