Git Product home page Git Product logo

wrapper-piper's Introduction

WRAPPER PIPER

This microservice is in charge of, through an endpoint, receiving a list of ids of locations previously added with the locstorager service, sending this list of ids to an input queue, searching the locations corresponding to this list of ids, extracting their latitude and longitude to calculate the distance of these locations using the Euclidean distance formula.

The idea behind this project is to fulfill some specific requirements that consist in calculating the distance with the euclidean formula, for this, two microservices are requested, one with the purpose of saving the locations with name, latitude and longitude, returning an id, locstorager service and another, (this one) to send a list of ids that calculate the distance between the two points sent.

My approach was based on using a vertical slice architecture because of the very specific requirements and the ease of maintaining a feature in my opinion.

I have left one package out of the main code structure, which is the database access, because in the feature package, called methods, I have added a data access layer with interfaces to decouple the code from the database manager as much as possible, thus fulfilling an important SOLID principle such as dependency inversion. If tomorrow I change the type of database manager or want to store the data or query it in a different way, I would not have to change my methods, I would simply change the implementation.

The wrapper-piper project structure

.
├── \
├── config.py
├── delivery_tables.sql
├── docker-compose.yml
├── Dockerfile
├── env.example
├── envrc.example
├── README.md
├── redis.conf
├── requirements.txt
├── run.py
├── setup.cfg
├── setup.py
└── src
    ├── calculator
    │   ├── calc.py
    │   ├── data_layer
    │   │   ├── data_access_impl.py
    │   │   ├── data_access_interface.py
    │   │   └── __init__.py
    │   ├── http_ids_handler.py
    │   ├── http_job_handler.py
    │   ├── __init__.py
    │   ├── job_results.py
    │   ├── models
    │   │   ├── __init__.py
    │   │   └── location.py
    │   ├── routes.py
    │   └── task.py
    ├── database
    │   ├── database_interface.py
    │   ├── __init__.py
    │   ├── postgres.py
    │   └── redis_mod.py
    └── __init__.py

Requirements

  • Python 3.11
  • Docker
  • Docker Compose
  • Redis
  • Postgres

Running

  1. Clone the repo
git clone https://github.com/Edmartt/wrapper-piper.git
  1. Browse into the project folder
cd wrapper-piper/

Development Version with Flask

  1. Create a virtual environment
python3 -m venv <virtual environment name>
  1. Activate virtual environment
source env/bin/activate
  1. Install dependencies
pip3 install -r requirements
  1. Run
flask run -p <port>

Note

We need to run with custom ports because this is the microservice that process the ids stored by another service that we'll have running in a default port (or maybe a custom one)

Running with Docker

  1. Pull the image from Dockerhub
docker pull edmartt/wrapper-piper
  1. Create a container
docker run --rm -p <host-port:docker-port> --env-file .env edmartt/wrapper-piper
Note

If we try to send requests to this service when is running alone with docker, we'll get an error because we don't have a database with the records for processing

Deploying all the services with Docker Compose

  1. set a .env file following the env.example
  2. Run the following command
docker-compose up

Now you're ready for testing the services. Please read the api documentation here >>> API DOCS

wrapper-piper's People

Contributors

edmartt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.