Skip to main content

A set of utilities for placing a message onto a queue for an emailer listener to receive

Project description

rabbitmq-email-notifier

python template for etd projects

Using this Repository

Read the wiki in the rabbitmq-email-notifier repo for instructions on how to set up the template and badge for your repository: https://github.com/harvard-lts/rabbitmq-email-notifier/wiki

Local setup

  1. Make a copy of the .env.example to .env and modify the user and password variables.

  2. Start the container

docker-compose -f docker-compose-local.yml up -d --build --force-recreate

Testing

  1. Start the container up as described in the Local Setup instructions.

  2. Exec into the container:

docker exec -it rabbitmq-email-notifier bash
  1. Run the tests
pytest
  1. Stop the container:

Start the container

docker-compose -f docker-compose-local.yml down

This command stops and removes all containers specified in the docker-compose-local.yml configuration. This command can be used in place of the 'stop' and 'rm' commands.

docker-compose -f docker-compose-local.yml down

Deployment

Dev

Dev deployment will occur using Jenkins. To trigger the development deployment, commit and push to the 'trial' or 'main' branch.

QA

QA is hosted on servers that contain L4 data. Jenkins is not permitted to deploy to these servers so for QA, Jenkins will only perform the build. To deploy:

  1. Commit and push to 'main'.
  2. If any IF changes happened, use ansible deploy commands from the ETD-IF project. Otherwise, manually restart the stack on the server that hosts QA.

Prod

Deploying to prod requires that the code be tagged in 'main'. That means the code should be stable and ready for a release.

  1. Create the tag and push to the repo if this hasn't been done. 2.Open Jenkins 3.Click on the "Branches" tab. NOTE: you should see a pipeline with your new tag. (if not, click on the "scan repository now" link in the sidebar.) 4.Click on the green play (triangle) button to start the build 5.Follow the build progress using the blue ocean view 6.The build process should end with a green status. the docker image is now ready for deployment to prod. 7.Work with ops to deploy to prod using the ETD-IF project.

Prerequisites to running docker locally

  • Requires telemetry/jaeger docker running
  • Make sure .env has JAEGER_NAME and JAEGER_SERVICE_NAME (see .env.example)
    • Note JAEGER_NAME must have local ip (if on vpn go to Cisco Icon -> Show Statistics Window -> CLient Address (IPv4)
  • start jaeger docker
  • docker pull jaegertracing/all-in-one:latest followed by
  • docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 -e COLLECTOR_OTLP_ENABLED=true -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 14250:14250 -p 14268:14268 -p 14269:14269 -p 9411:9411 jaegertracing/all-in-one:latest
  • You can now run hello world, and do testing

Run hello world example locally

  • Clone this repo from github

  • Create the .env by copying the .example.env cp .env.example .env

  • Replace rabbit connect value with dev values (found in 1Password LTS-ETD)

  • Replace the CONSUME_QUEUE_NAME and PUBLISH_QUEUE_NAME with a unique name for local testing (eg - add your initials to the end of the queue names)

  • Start up docker
    docker-compose -f docker-compose-local.yml up --build -d --force-recreate

  • Bring up DEV ETD Rabbit UI

  • Look for CONSUME_QUEUE_NAME queue

  • Exec into the docker container docker exec -it rabbitmq-email-notifier bash

  • Run invoke task python script python3 scripts/invoke-task.py

  • Look for PUBLISH_QUEUE_NAME queue, and get the message in the RabbitMQ UI

  • and/or tail to see activity

Manually placing a message on the queue

  • Open the queue in the RabbitMQ UI
  • Click on the CONSUME_QUEUE_NAME queue (the name that you assigned this env value to)
  • Open Publish Message
  • Set a property of content_type to application/json
  • Set the Payload to the following JSON content {"id": "da28b429-e006-49a5-ae77-da41b925bd85","task": "rabbitmq-email-notifier.tasks.send_to_base","args": [{"hello":"world"}]}

Unit Testing

  • exec into docker
  • > pytest tests/unit
  • Note, integration tests are run as part of github actions, not locally

Using OpenTelemetry for tracing

This app uses OpenTelemetry (https://opentelemetry.io/) for live tracing. To see how it is implemented in the application, refer to this wiki: https://wiki.harvard.edu/confluence/display/LibraryTechServices/OpenTelemetry

Build and publish the package

Prepare the distribution

  • Update the version number in setup.py
  • To publish a pre-release version, add a letter and a number after the version number e.g. 0.0.1a1
  • Remove the old dist/ directory from the previous build if necessary

Build the distribution

Once inside the container, build the distribution.

python3 setup.py sdist bdist_wheel

A new directory dist will be created in the container.

Register for an account

Register for an account on the test python package repository. Enable two-factor authentication for logins. Create a token.

Upload package to the test repository

Publish the package to the test repository testpypi before publishing it to the production repository.

python3 -m twine upload --repository testpypi dist/*

Test the package

Open the package in the repository and view the version history.

https://test.pypi.org/project/rabbitmq-email-notifier/0.0.4/

More information

Read the documenation for more information on building and publishing the distribution.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rabbitmq-email-notifier-0.0.5.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

rabbitmq_email_notifier-0.0.5-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file rabbitmq-email-notifier-0.0.5.tar.gz.

File metadata

File hashes

Hashes for rabbitmq-email-notifier-0.0.5.tar.gz
Algorithm Hash digest
SHA256 dd646d3f2dfa9f9344966d5f410624dedb554f62e4e22f43698e7a94f8eb0edf
MD5 31715b85a2c9d901de1613928d76b18f
BLAKE2b-256 d98f9f53701f7d879f96ec97b911ac74c19787bfdf6ab5f69ebb9ebb7421d6f0

See more details on using hashes here.

File details

Details for the file rabbitmq_email_notifier-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for rabbitmq_email_notifier-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 eb8d457d092284cb34f7bae0e0c9c6b0f3dd8deda0eba88d341de503504bf10b
MD5 f76553a1998b5146859b097fd9d8e141
BLAKE2b-256 2bc60fb7a654f6832e945a33532ed9067bfda0c1f721e0f2dac0402739e7b7c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page