Giter Club home page Giter Club logo

loyalty-points-project-python's Introduction


Loyalty points project in Python with Temporal

โ—ฆ Unlock your rewards with a loyalty points Workflow!

โ—ฆ Developed with the software and tools listed below.

Python Markdown

GitHub top language GitHub code size in bytes GitHub commit activity GitHub license

๐Ÿ“’ Table of Contents


๐Ÿ“ Overview

The Loyalty Points Project in Python is a codebase that implements a loyalty program management system with the Temporal SDK. It provides a Flask application with REST API endpoints for managing loyalty points, such as adding or removing points and sending emails. The project utilizes the Temporal workflow engine to handle program logic, ensuring efficient and reliable execution. With its robust functionality and modular design, the Loyalty Points Project offers a valuable solution for businesses looking to implement and manage their loyalty programs effectively.


โš™๏ธ Features

Feature Description
โš™๏ธ Architecture The codebase follows a microservices architecture pattern, where different components handle specific functionalities. The Flask application (app.py) serves as the frontend, providing REST API endpoints for managing the loyalty program. The LoyaltyProgram workflow (loyalty_workflow.py) implements the program logic, including point management and email sending. The worker (main.py) listens to a task queue and runs the LoyaltyProgram workflow and the send_email activity. The codebase uses the Temporal workflow engine to handle the program logic efficiently. The architecture allows for scalability and modularity, with each component responsible for a specific task.
๐Ÿ“– Documentation The codebase lacks comprehensive documentation. Although some files have docstrings explaining their purpose, there is a lack of high-level documentation, architectural overview, and usage instructions. Improving the documentation would make it easier for developers to understand the codebase and contribute to the project.
๐Ÿ”— Dependencies The codebase relies on several external libraries and systems. Notable dependencies include Flask for building the REST API, Temporal as the workflow engine, and Redis for task queue management. The codebase also relies on the standard Python libraries such as os, requests, and json. The dependencies are managed using Pipenv, as seen in the Pipfile and Pipfile.lock files.
๐Ÿงฉ Modularity The codebase demonstrates a reasonable level of modularity. Each file serves a specific purpose, such as defining data classes, implementing workflows, or managing the worker. The codebase follows a logical separation of concerns, making it easier to maintain and extend. However, there is room for improvement in organizing the code into more granular and interchangeable components, promoting reusability and maintainability.
โœ”๏ธ Testing The codebase does not have comprehensive test coverage. There are no specific test files or test folders present. Implementing tests using a testing framework like pytest or unittest would help ensure the correctness of the codebase and facilitate future development. The lack of testing strategies and tools poses a risk to the stability and reliability of the project.
โšก๏ธ Performance The codebase does not have any performance optimizations explicitly implemented. However, the usage of the Temporal workflow engine can improve efficiency by handling the program logic in a distributed manner. The codebase does not exhibit any resource-intensive operations or performance bottlenecks. Proper profiling and optimization techniques can be applied if performance becomes a concern in the future.
๐Ÿ” Security The codebase does not explicitly demonstrate security measures. However, since it utilizes Flask, it can leverage Flask's security features such as protecting against common web vulnerabilities (e.g., Cross-site Scripting (XSS), Cross-Site Request Forgery (

๐Ÿ“‚ Project Structure

repo
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ activity.py
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ loyalty_workflow.py
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ poetry.lock
โ”œโ”€โ”€ pyproject.toml
โ””โ”€โ”€ scripts
    โ”œโ”€โ”€ aaron.py
    โ””โ”€โ”€ script.py

2 directories, 9 files

๐Ÿงฉ Modules

Root
File Summary
activity.py The code snippet defines a data class called Email with attributes for recipient, subject, and body. It also defines an activity function send_email that takes an Email object as input and prints the email details. The function returns a success message.
loyalty_workflow.py This code snippet implements a LoyaltyProgram workflow that allows adding and removing points, sending emails, and tracking loyalty details.
app.py This code snippet is a Flask application that provides REST API endpoints for managing a loyalty program. It uses the Temporal workflow engine to handle the program logic, including starting the program, spending/add points, and exiting the program for a specific user.
main.py The provided code snippet connects to a local client and initializes a worker. The worker is responsible for executing the LoyaltyProgram workflow and the send_email activity. It listens to a task queue named "loyalty-program-task-queue" and runs indefinitely.
Scripts
File Summary
aaron.py The code snippet utilizes the "os" module to make 124 POST requests to a local API endpoint, each with a different value for the "i" parameter in the URL. The requests use the "curl" command to send a POST request with a fixed payload of 500 points.
script.py The code snippet uses the os module to make HTTP POST requests to a local server. It iterates from 1 to 124, sending requests to increment points for each iteration. Each request adds 100 points to the specified endpoint.

๐Ÿš€ Getting Started

โœ”๏ธ Prerequisites

Before you begin, ensure that you have the following prerequisites installed:

  • โ„น๏ธ Requirement 1
  • โ„น๏ธ Requirement 2
  • โ„น๏ธ ...

๐Ÿ“ฆ Installation

  1. Clone the loyalty-points-project-python repository:
git clone https://github.com/rachfop/loyalty-points-project-python
  1. Change to the project directory:
cd loyalty-points-project-python

๐Ÿ Usage

Start a Workflow

# terminal one
poetry run python app.py
# terminal two
poetry run python main.py

Example commands

curl -X POST http://localhost:5000/123
curl -X POST http://localhost:5000/123/add_points/1000
curl -X POST http://localhost:5000/123/add_points/30
curl -X POST http://localhost:5000/123/add_points/20
curl -X GET http://localhost:5000/123

Get points

curl -X GET http://localhost:5000/123

Add points

curl -X POST http://localhost:5000/123/add_points/850

Spend points

curl -X POST http://localhost:5000/123/spend_points/10

End Workflow

curl -X DELETE http://localhost:5000/123/exit

Terminate

temporal workflow terminate --workflow-id 123

Reset

Execute Batch Reset command:

temporal workflow reset-batch --query "WorkflowType='LoyaltyProgram'" --reason "Sev2: id.1259" --type LastWorkflowTask

Dry run a Batch Reset command:

temporal workflow reset-batch --query "WorkflowType='LoyaltyProgram'" --reason "Sev2: id.1259" --type LastWorkflowTask --dry-run
# create (not needed)
temporal operator search-attribute create --name points --type int
# list
temporal operator search-attribute list
# describe
temporal workflow list \
  --query "(points >= 1000) AND ExecutionStatus='Running'"

๐Ÿ—บ Roadmap

  • โ„น๏ธ Task 1: Implement Activity
  • โ„น๏ธ Task 2: Send Grid/Twilio API
  • โ„น๏ธ ...

๐Ÿค Contributing

Contributions are always welcome! Please follow these steps:

  1. Fork the project repository. This creates a copy of the project on your account that you can modify without affecting the original project.
  2. Clone the forked repository to your local machine using a Git client like Git or GitHub Desktop.
  3. Create a new branch with a descriptive name (e.g., new-feature-branch or bugfix-issue-123).
git checkout -b new-feature-branch
  1. Make changes to the project's codebase.
  2. Commit your changes to your local branch with a clear commit message that explains the changes you've made.
git commit -m 'Implemented new feature.'
  1. Push your changes to your forked repository on GitHub using the following command
git push origin new-feature-branch
  1. Create a new pull request to the original project repository. In the pull request, describe the changes you've made and why they're necessary. The project maintainers will review your changes and provide feedback or merge them into the main branch.

loyalty-points-project-python's People

Contributors

rachfop avatar

loyalty-points-project-python's Issues

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.