prod-wag-backend-automate-s.../BankServices/RoutineEmailService
Berkay e0ae1ee80a appender events and applications are updated 2025-05-06 12:03:58 +03:00
..
templates Bank Services tested and completed 2025-04-21 14:33:25 +03:00
Dockerfile updated Dockerfile 2025-04-25 15:46:14 +03:00
README.md routine crontab service tested and completed added to Readme.md 2025-04-25 16:07:17 +03:00
app.py appender events and applications are updated 2025-05-06 12:03:58 +03:00
entrypoint.sh updated Dockerfile 2025-04-25 16:01:46 +03:00
pyproject.toml Bank Services tested and completed 2025-04-21 14:33:25 +03:00
run_app.sh updated Dockerfile 2025-04-25 16:01:46 +03:00

README.md

Routine Email Service

Overview

This service sends automated email reports about account records at scheduled times using cron. It retrieves account records from a PostgreSQL database, formats them into an HTML email, and sends them to specified recipients.

Environment Setup

The service requires the following environment variables:

Email Configuration

  • EMAIL_HOST: SMTP server address (e.g., "10.10.2.34")
  • EMAIL_USERNAME: Email sender address (e.g., "example@domain.com")
  • EMAIL_PASSWORD: Email password (sensitive)
  • EMAIL_PORT: SMTP port (e.g., 587)
  • EMAIL_SEND: Flag to enable/disable email sending (1 = enabled)

Database Configuration

  • DB_HOST: PostgreSQL server address (e.g., "10.10.2.14")
  • DB_USER: Database username (e.g., "postgres")
  • DB_PASSWORD: Database password (sensitive)
  • DB_PORT: Database port (e.g., 5432)
  • DB_NAME: Database name (e.g., "postgres")

Cron Job Configuration

The service is configured to run daily at 11:00 Istanbul Time (08:00 UTC). This is set up in the entrypoint.sh script.

Docker Container Setup

Key Files

  1. Dockerfile: Defines the container image with Python and cron

  2. entrypoint.sh: Container entrypoint script that:

    • Creates an environment file (/env.sh) with all configuration variables
    • Sets up the crontab to run run_app.sh at the scheduled time
    • Starts the cron service
    • Tails the log file for monitoring
  3. run_app.sh: Script executed by cron that:

    • Sources the environment file to get all configuration
    • Exports variables to make them available to the Python script
    • Runs the Python application
    • Logs environment and execution results

Environment Variable Handling

Cron jobs run with a minimal environment that doesn't automatically include Docker container environment variables. Our solution:

  1. Captures all environment variables from Docker to a file at container startup
  2. Has the run_app.sh script source this file before execution
  3. Explicitly exports all variables to ensure they're available to the Python script

Logs

Logs are written to /var/log/cron.log and can be viewed with:

docker exec routine_email_service tail -f /var/log/cron.log

Manual Execution

To run the service manually:

docker exec routine_email_service /run_app.sh

Docker Compose Configuration

In the docker-compose.yml file, the service needs an explicit entrypoint configuration:

entrypoint: ["/entrypoint.sh"]

This ensures the entrypoint script runs when the container starts.