File tree Expand file tree Collapse file tree 5 files changed +29
-14
lines changed
Expand file tree Collapse file tree 5 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ def ssh_execute(
1414 command : str ,
1515 ssh_hook : SSHHook | None = None ,
1616 * ,
17- max_tries : int = 10 ,
17+ max_tries : int = 30 ,
1818) -> str :
1919 """Execute the given `command` via the `ssh_hook`.
2020
@@ -41,7 +41,7 @@ def ssh_execute(
4141 logging .error (f"Execution of SSH command failed too often: { command = } " )
4242 raise AirflowFailException ("Execution of SSH command failed too often." )
4343
44- sleep (30 * call_count ) # no sleep in the first iteration
44+ sleep (60 * call_count ) # no sleep in the first iteration
4545 call_count += 1
4646
4747 try :
Original file line number Diff line number Diff line change @@ -65,11 +65,11 @@ def test_ssh_execute_too_many_tries(mock_sleep: MagicMock) -> None:
6565 # given
6666 ssh_hook = MagicMock ()
6767 bad_return = (254 , b"command output" , b"" )
68- ssh_hook .exec_ssh_client_command .side_effect = [bad_return ] * 11
68+ ssh_hook .exec_ssh_client_command .side_effect = [bad_return ] * 31
6969
7070 # when
7171 with pytest .raises (AirflowFailException ):
7272 ssh_execute ("my_command" , ssh_hook )
7373
74- assert mock_sleep .call_count == 10 # noqa: PLR2004
75- assert ssh_hook .exec_ssh_client_command .call_count == 10 # noqa: PLR2004
74+ assert mock_sleep .call_count == 30 # noqa: PLR2004
75+ assert ssh_hook .exec_ssh_client_command .call_count == 30 # noqa: PLR2004
Original file line number Diff line number Diff line change @@ -319,8 +319,9 @@ services:
319319 retries : 5
320320 start_period : 30s
321321 restart : always
322- # # Uncomment for local development so that changes to webapp are immediately active
323- # volumes:
322+ volumes :
323+ - ./webapp_logs:/app/logs
324+ # Uncomment for local development so that changes to webapp are immediately active
324325 # - ./webapp:/app/webapp
325326 # - ./shared:/app/webapp/shared
326327
Original file line number Diff line number Diff line change 1+ """Test configuration for webapp tests."""
2+
3+ import os
4+
5+ os .environ ["IS_PYTEST_RUN" ] = "1" # Indicate that tests are running
Original file line number Diff line number Diff line change 11"""Utilities for the streamlit app."""
22
33import io
4+ import logging
45import os
56import traceback
6- from datetime import datetime
77from pathlib import Path
88
99import plotly .graph_objects as go
10- import pytz
1110import streamlit as st
1211from PIL import Image
1312
@@ -47,20 +46,30 @@ class QueryParams:
4746DEFAULT_MAX_AGE_OVERVIEW = 30 # days
4847DEFAULT_MAX_AGE_STATUS = 90 # days
4948
49+ # Configure logging
50+ logging .basicConfig (
51+ level = logging .INFO ,
52+ format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" ,
53+ handlers = [
54+ logging .FileHandler ("/app/logs/webapp.log" )
55+ if os .getenv ("IS_PYTEST_RUN" , "0" ) != "1"
56+ else None ,
57+ logging .StreamHandler (), # Keep console output for debugging
58+ ],
59+ )
60+ logger = logging .getLogger (__name__ )
61+
5062
5163def _log (item_to_log : str | Exception , extra_msg : str = "" ) -> None :
5264 """Write a log message and show it if it's an exception."""
53- now = datetime .now (tz = pytz .UTC ).strftime ("%Y-%m-%d %H:%M:%S.%f" )
54-
5565 if isinstance (item_to_log , Exception ):
5666 if extra_msg :
5767 st .write (extra_msg )
5868 st .write (item_to_log )
5969 msg = f"{ extra_msg } { item_to_log } \n { traceback .format_exc ()} "
70+ logger .error (msg , exc_info = True )
6071 else :
61- msg = f"{ now } : { item_to_log } "
62-
63- os .write (1 , f"{ msg } \n " .encode ())
72+ logger .info (item_to_log )
6473
6574
6675def empty_to_none (value : str ) -> str | None :
You can’t perform that action at this time.
0 commit comments