Skip to content

Commit

Permalink
fix: Fix threading
Browse files Browse the repository at this point in the history
  • Loading branch information
WCY-dt committed Dec 17, 2024
1 parent b8047e7 commit 8cd1968
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
18 changes: 4 additions & 14 deletions my-github-2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dotenv import load_dotenv
import os
import logging
from multiprocessing import Process
import threading
from flask_sqlalchemy import SQLAlchemy
import json

Expand Down Expand Up @@ -63,9 +63,6 @@ class UserContext(db.Model):
db.session.commit()


logging.info("Preparation complete")


@app.before_request
def before_request():
if (
Expand All @@ -77,13 +74,11 @@ def before_request():

@app.route("/", methods=["GET"])
def index():
logging.info("/")
return render_template("login.html")


@app.route("/login")
def login():
logging.info("/login")
github_authorize_url = "https://github.com/login/oauth/authorize"
return redirect(
f"{github_authorize_url}?client_id={app.config['CLIENT_ID']}&scope=repo,read:org"
Expand All @@ -92,7 +87,6 @@ def login():

@app.route("/callback")
def callback():
logging.info("/callback")
code = request.args.get("code")
token_response = requests.post(
"https://github.com/login/oauth/access_token",
Expand All @@ -111,7 +105,6 @@ def callback():

@app.route("/dashboard", methods=["GET"])
def dashboard():
logging.info("/dashboard")
access_token = session.get("access_token")
headers = {"Authorization": f"bearer {access_token}"}
logging.info(f"access_token: {access_token}")
Expand All @@ -133,7 +126,6 @@ def dashboard():

@app.route("/load", methods=["POST"])
def load():
logging.info("/load")
data = request.json

access_token = data.get("access_token")
Expand Down Expand Up @@ -168,15 +160,14 @@ def fetch_data():
db.session.add(user_context)
db.session.commit()

fetch_process = Process(target=fetch_data)
fetch_process.start()
fetch_thread = threading.Thread(target=fetch_data)
fetch_thread.start()

return jsonify({"redirect_url": url_for("wait")})


@app.route("/wait", methods=["GET"])
def wait():
logging.info("/wait")
username = session.get("username")
user_context = UserContext.query.filter_by(username=username).first()
if user_context:
Expand All @@ -187,7 +178,6 @@ def wait():

@app.route("/display", methods=["GET"])
def display():
logging.info("/display")
username = session.get("username")
user_context = UserContext.query.filter_by(username=username).first()
if user_context:
Expand All @@ -200,9 +190,9 @@ def display():

@app.route("/static/<path:filename>", methods=["GET"])
def static_files(filename):
logging.info(f"/static/{filename}")
return send_from_directory("static", filename)



if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
2 changes: 1 addition & 1 deletion my-github-2024.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WorkingDirectory=/var/www/my-github-2024
Environment="PATH=/var/www/my-github-2024/venv/bin"
Environment="FLASK_ENV=production"
EnvironmentFile=/var/www/my-github-2024/.env
ExecStart=/var/www/my-github-2024/venv/bin/gunicorn --workers 5 --bind 0.0.0.0:5000 my-github-2024:app
ExecStart=/var/www/my-github-2024/venv/bin/gunicorn --workers 5 --threads 200 --worker-class gthread --bind 0.0.0.0:5000 my-github-2024:app
Restart=on-failure

[Install]
Expand Down

0 comments on commit 8cd1968

Please sign in to comment.