Skip to content

Commit

Permalink
test-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
pcanto-hopeit committed Feb 21, 2024
1 parent 55fabab commit fc3fe93
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 15 deletions.
3 changes: 1 addition & 2 deletions apps/examples/simple-example/config/app-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
},
"events": {
"setup_something": {
"type": "SETUP",
"setting_keys": ["fs_storage"]
"type": "SETUP"
},
"list_somethings": {
"type": "GET",
Expand Down
2 changes: 1 addition & 1 deletion engine/src/hopeit/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class EventType(str, Enum):
STREAM: event triggered read events from stream. Can be started and stopped.
SERVICE: event executed on demand or continuously. Long lived. Can be started and stopped.
MULTIPART: event triggered from api postform-multipart request via endpoint.
SETUP: event that is executed once when service is starting
SETUP: event that is executed once when service is starting
"""
GET = 'GET'
POST = 'POST'
Expand Down
25 changes: 15 additions & 10 deletions engine/src/hopeit/server/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ def _enable_cors(prefix: str, cors: CorsConfig):
cors.add(route)


async def _setup_app_event_routes(app_engine: AppEngine, plugin: Optional[AppEngine] = None):
async def _setup_app_event_routes(
app_engine: AppEngine, plugin: Optional[AppEngine] = None
):
"""
Setup http routes for existing events in app,
in existing web_server global instance.
Expand Down Expand Up @@ -546,7 +548,7 @@ async def _execute_setup_event(
app_engine: AppEngine,
plugin: Optional[AppEngine],
event_name: str,
) -> EventContext:
) -> Optional[EventPayload]:
"""
Executes event of SETUP type, on server start
"""
Expand All @@ -570,10 +572,11 @@ async def _execute_setup_event(
return res


def _request_start(app_engine: AppEngine,
plugin: AppEngine,
event_name: str,
event_settings: EventSettings,
def _request_start(
app_engine: AppEngine,
plugin: AppEngine,
event_name: str,
event_settings: EventSettings,
request: web.Request,
) -> EventContext:
"""
Expand All @@ -585,7 +588,7 @@ def _request_start(app_engine: AppEngine,
event_name=event_name,
settings=event_settings,
track_ids=_track_ids(request),
auth_info=auth_info_default
auth_info=auth_info_default,
)
logger.start(context)
return context
Expand All @@ -595,12 +598,14 @@ def _extract_auth_header(request: web.Request, context: EventContext) -> Optiona
return request.headers.get("Authorization")


def _extract_refresh_cookie(request: web.Request, context: EventContext) -> Optional[str]:
def _extract_refresh_cookie(
request: web.Request, context: EventContext
) -> Optional[str]:
return request.cookies.get(f"{context.app_key}.refresh")


def _ignore_auth(request: web.Request, context: EventContext) -> str:
return 'Unsecured -'
return "Unsecured -"


AUTH_HEADER_EXTRACTORS = {
Expand Down Expand Up @@ -1005,4 +1010,4 @@ def serve(
api_auto=sys_args.api_auto,
start_streams=sys_args.start_streams,
enabled_groups=sys_args.enabled_groups,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
},
"classes": "EVENT"
},
"simple_example.${APPS_ROUTE_VERSION}.setup_something": {
"data": {
"id": "simple_example.${APPS_ROUTE_VERSION}.setup_something",
"content": "simple_example.${APPS_ROUTE_VERSION}\nsetup_something"
},
"classes": "EVENT"
},
"simple_example.${APPS_ROUTE_VERSION}.list_somethings.GET": {
"data": {
"id": "simple_example.${APPS_ROUTE_VERSION}.list_somethings.GET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
}
},
"events": {
"setup_something": {
"type": "SETUP",
"plug_mode": "Standalone",
"connections": [],
"auth": [],
"setting_keys": [],
"dataobjects": [],
"group": "DEFAULT"
},
"list_somethings": {
"type": "GET",
"plug_mode": "Standalone",
Expand Down Expand Up @@ -356,7 +365,28 @@
}
},
"effective_settings": {
"list_somethings": {
"setup_something": {
"response_timeout": 60.0,
"logging": {
"extra_fields": [],
"stream_fields": [
"stream.name",
"stream.msg_id",
"stream.consumer_group"
]
},
"stream": {
"timeout": 60.0,
"target_max_len": 0,
"throttle_ms": 0,
"step_delay": 0,
"batch_size": 100,
"compression": "lz4",
"serialization": "json+base64"
},
"extras": {}
},
"list_somethings": {
"response_timeout": 60.0,
"logging": {
"extra_fields": [],
Expand Down Expand Up @@ -850,6 +880,15 @@
"dataobjects": [],
"group": "DEFAULT"
},
"simple_example.${APPS_ROUTE_VERSION}.setup_something": {
"type": "SETUP",
"plug_mode": "Standalone",
"connections": [],
"auth": [],
"setting_keys": [],
"dataobjects": [],
"group": "DEFAULT"
},
"simple_example.${APPS_ROUTE_VERSION}.list_somethings": {
"type": "GET",
"plug_mode": "Standalone",
Expand Down Expand Up @@ -1161,7 +1200,10 @@
"streams": {
"stream_manager": "hopeit.streams.NoStreamManager",
"connection_str": "<<NoStreamManager>>",
"delay_auto_start_seconds": 3
"delay_auto_start_seconds": 3,
"initial_backoff_seconds": 1.0,
"max_backoff_seconds": 60.0,
"num_failures_open_circuit_breaker": 1
},
"logging": {
"log_level": "DEBUG",
Expand Down

0 comments on commit fc3fe93

Please sign in to comment.