Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/test-email.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test Email Notification

on:
workflow_dispatch: # run manually from Actions tab

jobs:
send-test-email:
runs-on: ubuntu-latest
steps:
- name: Send test email
uses: dawidd6/action-send-mail@v3
with:
server_address: ${{ secrets.SMTP_SERVER }}
server_port: ${{ secrets.SMTP_PORT }}
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: "GitHub Actions Email Test"
to: ${{ secrets.NOTIFY_EMAIL_TO }}
from: ${{ secrets.NOTIFY_EMAIL_FROM }}
body: |
This is a test email sent from GitHub Actions.
If you received this, your SMTP settings are correct.
53 changes: 43 additions & 10 deletions .github/workflows/testsPython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,46 @@ jobs:
# is scaffolded to facilitate sending notifications based
# on the test results.
notifications:
needs: python-unit-tests
runs-on: ubuntu-latest
steps:
- name: Notify on test results
run: |
if [ "${{ needs.python-unit-tests.result }}" == "success" ]; then
echo "success notifications go here"
else
echo "failure notifications go here"
fi
needs: python-unit-tests
if: always()
runs-on: ubuntu-latest
steps:
- name: Send success email
if: ${{ needs.python-unit-tests.result == 'success' }}
uses: dawidd6/action-send-mail@v3
with:
server_address: ${{ secrets.SMTP_SERVER }}
server_port: ${{ secrets.SMTP_PORT }}
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: "Python Unit Tests Passed"
to: ${{ secrets.NOTIFY_EMAIL_TO }}
from: ${{ secrets.NOTIFY_EMAIL_FROM }}
body: |
🎉 Python unit tests succeeded!

Workflow: Python Unit Tests
Status: SUCCESS
Branch: ${{ github.ref }}
Commit: ${{ github.sha }}

- name: Send failure email
if: ${{ needs.python-unit-tests.result != 'success' }}
uses: dawidd6/action-send-mail@v3
with:
server_address: ${{ secrets.SMTP_SERVER }}
server_port: ${{ secrets.SMTP_PORT }}
username: ${{ secrets.SMTP_USERNAME }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: "Python Unit Tests FAILED"
to: ${{ secrets.NOTIFY_EMAIL_TO }}
from: ${{ secrets.NOTIFY_EMAIL_FROM }}
body: |
❌ Python unit tests failed.

Workflow: Python Unit Tests
Status: FAILURE
Branch: ${{ github.ref }}
Commit: ${{ github.sha }}

Check the GitHub Actions logs for details.
17 changes: 16 additions & 1 deletion app/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
import logging
import sys

from app.settings import LOGGING_LEVEL
from app.settings import LOGGING_LEVEL, SUPPRESS_FUNCTION_LOGS


_SUPPRESS_PATTERNS = ("Updated messages", "Initial response", "Updated response", "OpenAI response", "Sending messages to OpenAI")


class _SuppressFunctionResponseFilter(logging.Filter):
def filter(self, record):
msg = record.getMessage()
return not any(pattern in msg for pattern in _SUPPRESS_PATTERNS)


def setup_logging(level: int = LOGGING_LEVEL) -> logging.Logger:
Expand All @@ -27,7 +36,13 @@ def setup_logging(level: int = LOGGING_LEVEL) -> logging.Logger:
handlers=[logging.StreamHandler(sys.stdout)], # This logs to console
)

if SUPPRESS_FUNCTION_LOGS:
for handler in logging.getLogger().handlers:
handler.addFilter(_SuppressFunctionResponseFilter())

logging.getLogger("httpx").setLevel(logging.WARNING)
logging.getLogger("openai._base_client").setLevel(logging.WARNING)
logging.getLogger("httpcore").setLevel(logging.WARNING)

return logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# General settings
LOGGING_LEVEL = int(os.getenv("LOGGING_LEVEL", str(logging.INFO)))
SUPPRESS_FUNCTION_LOGS = os.getenv("SUPPRESS_FUNCTION_LOGS", "false").lower() == "true"


# LLM/OpenAI API settings
Expand Down
Loading
Loading