Skip to content

Email subscriptions newsletter build by using Rust and actix-web.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

drconopoima/newsletter-rs

Repository files navigation

newsletter-rs

Email subscriptions newsletter build by using Rust and actix-web.

Pre-requisites

You'll need to install:

Install Podman

On Ubuntu/Debian

apt install podman

On CentOs >= 8

dnf install podman

On Max OS X

brew install podman

Install PostgreSQL client

On Ubuntu/Debian

apt install postgresql-client

On CentOs >= 8

dnf install postgresql

On Mac OS X using Homebrew

brew install libpq
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc

Launch

Launch a (migrated) Postgres database via a container engine (default Podman, optionally Docker):

./scripts/launch_postgres.bash

Run application using cargo:

cargo run

Send subscription entries by using the /subscription endpoint

curl -s -w'\n%{http_code}\n' "http://127.0.0.1:8000/subscription" -d "email=email%40drconopoima.com&name=Jane%20Doe"

Test correct operation by using /healthcheck endpoint

curl -s -w'\n%{http_code}\n' http://127.0.0.1:65080/healthcheck | jq '.'
{
  "status": "pass",
  "checks": {
    "postgres_read": {
      "status": "pass",
      "time": "2022-03-06T23:32:10.555806Z",
      "output": "",
      "version": "PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit"
    },
    "postgres_write": {
      "status": "pass",
      "time": "2022-03-06T23:32:10.556877Z",
      "pg_is_in_recovery": false,
      "output": "",
      "version": "PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit"
    }
  },
  "output": "",
  "time": "2022-03-06T23:32:10.547917389Z",
  "version": "0.1.0"
}
200

Customize logging level

By default, newsletter-rs is configured with Actix Logger Middleware in INFO logging level. It can be customized with RUST_LOG environment variable at runtime.

    export RUST_LOG=DEBUG # Valid options trace|debug|info|warn|error|fatal
    cargo run

Enable backtrace

    export RUST_BACKTRACE=1 # Valid options 1|full
    cargo run

How to build

Using cargo:

cargo build

How to test

Using cargo:

cargo test 

Logging output from test logs is suppressed. Set environment variable TEST_LOG for output:

TEST_LOG=true cargo test

To beautify the tracing output, you can use a process substitution and a JSON processing library, like jq:

while read -r line; do echo "${line}" | jq -R 'fromjson? | .'; done< <(TEST_LOG=true cargo test)

How to loadtest

Using K6

cargo run --release
k6 run --vus 200 ./testdata/k6_get_healthcheck.js --duration 60s
k6 run --vus 200 ./testdata/k6_post_subscription.js --duration 60s

Configuration

Each configuration parameter is obtained from files within relative directory 'configuration'. The base configuration file is main.yaml

You can generate custom override configuration files, and launch by using variable 'APP__ENVIRONMENT'

E.g. to launch with example production settings, you would use:

APP__ENVIRONMENT=production cargo run --release

You can override any parameter with environment variables, by using the prefix "APP__" and field separator "_":

  export APP__DATABASE_PASSWORD='Some$ecretPassword'
  APP__APPLICATION_PORT=8080 cargo run --release

Would be equivalent as fabricating a custom override configuration file:

application:
  port: 8080
database:
  password: 'Some$ecretPassword'

Database details

Check the database diagram section.

Database migration scripts notes

The default migration scripts included in ./migrations require at least Postgres 14 to work. You can replace scripts if need compatibility. Error in older versions 'syntax error at or near "TRIGGER"'.

About

Email subscriptions newsletter build by using Rust and actix-web.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published