Skip to content

rachfop/loyalty-points-project-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages