From aa9fce6a8e1adcd5aec7da412dfce451bf080ad8 Mon Sep 17 00:00:00 2001 From: Michael Herman Date: Tue, 29 Dec 2020 11:47:59 -0600 Subject: [PATCH 1/5] update requirements --- .python-version | 2 +- Dockerfile | 2 +- LICENSE | 2 +- docker-compose.yml | 2 +- project/client/static/main.js | 6 +++--- requirements.txt | 6 +++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.python-version b/.python-version index 1981190..6bd1074 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.8.0 +3.9.1 diff --git a/Dockerfile b/Dockerfile index c5b4822..04a5b83 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # base image -FROM python:3.8.0-alpine +FROM python:3.9.1-alpine # set working directory RUN mkdir -p /usr/src/app diff --git a/LICENSE b/LICENSE index a59e7e6..14a9bd9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Michael Herman +Copyright (c) 2020 Michael Herman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docker-compose.yml b/docker-compose.yml index 5b479bf..b4cd93c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.7' +version: '3.8' services: diff --git a/project/client/static/main.js b/project/client/static/main.js index 61c8bdc..f7a60fd 100644 --- a/project/client/static/main.js +++ b/project/client/static/main.js @@ -11,10 +11,10 @@ $('.btn').on('click', function() { method: 'POST' }) .done((res) => { - getStatus(res.data.task_id) + getStatus(res.data.task_id); }) .fail((err) => { - console.log(err) + console.log(err); }); }); @@ -38,6 +38,6 @@ function getStatus(taskID) { }, 1000); }) .fail((err) => { - console.log(err) + console.log(err); }); } diff --git a/requirements.txt b/requirements.txt index d90a786..6ef1064 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Flask==1.1.1 +Flask==1.1.2 Flask-Bootstrap==3.3.7.1 -Flask-Testing==0.7.1 -Flask-WTF==0.14.2 +Flask-Testing==0.8.1 +Flask-WTF==0.14.3 From 746d082414bca152d55b34a80cfbe765a458eae1 Mon Sep 17 00:00:00 2001 From: Amir Tadrisi Date: Mon, 17 Jan 2022 13:03:26 -0500 Subject: [PATCH 2/5] chore: bump versions --- Dockerfile | 2 +- requirements.txt | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 04a5b83..045e057 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # base image -FROM python:3.9.1-alpine +FROM python:3.10-alpine # set working directory RUN mkdir -p /usr/src/app diff --git a/requirements.txt b/requirements.txt index 6ef1064..1f9575f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ -Flask==1.1.2 +Flask==2.0.2 Flask-Bootstrap==3.3.7.1 Flask-Testing==0.8.1 -Flask-WTF==0.14.3 +Flask-WTF==1.0.0 +redis==4.1.1 +rq==1.10.1 \ No newline at end of file From ba0c025713180853fce61cbaad752d70965c43df Mon Sep 17 00:00:00 2001 From: Michael Herman Date: Tue, 18 Jan 2022 14:09:19 -0600 Subject: [PATCH 3/5] update dependencies --- .python-version | 2 +- LICENSE | 2 +- project/client/templates/_base.html | 8 +++----- project/server/__init__.py | 7 ++----- requirements.txt | 4 ++-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.python-version b/.python-version index 6bd1074..7b59a5c 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.9.1 +3.10.2 diff --git a/LICENSE b/LICENSE index 14a9bd9..b3f8034 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Michael Herman +Copyright (c) 2022 Michael Herman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/project/client/templates/_base.html b/project/client/templates/_base.html index 31ad653..870682b 100644 --- a/project/client/templates/_base.html +++ b/project/client/templates/_base.html @@ -7,9 +7,9 @@ - + - + {{ bootstrap.load_css() }} {% block css %}{% endblock %} @@ -24,9 +24,7 @@ {% include 'footer.html' %} - - - + {{ bootstrap.load_js() }} {% block js %}{% endblock %} diff --git a/project/server/__init__.py b/project/server/__init__.py index 8e0bc2b..b6d6127 100644 --- a/project/server/__init__.py +++ b/project/server/__init__.py @@ -4,10 +4,7 @@ import os from flask import Flask -from flask_bootstrap import Bootstrap - -# instantiate the extensions -bootstrap = Bootstrap() +from flask_bootstrap import Bootstrap4 def create_app(script_info=None): @@ -24,7 +21,7 @@ def create_app(script_info=None): app.config.from_object(app_settings) # set up extensions - bootstrap.init_app(app) + Bootstrap4(app) # register blueprints from project.server.main.views import main_blueprint diff --git a/requirements.txt b/requirements.txt index 1f9575f..834560b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ +Bootstrap-Flask==2.0.0 Flask==2.0.2 -Flask-Bootstrap==3.3.7.1 Flask-Testing==0.8.1 Flask-WTF==1.0.0 redis==4.1.1 -rq==1.10.1 \ No newline at end of file +rq==1.10.1 From 315d4379932d9e72b7fc91f8396e4aa0401e844f Mon Sep 17 00:00:00 2001 From: Michael Herman Date: Tue, 18 Jan 2022 14:50:17 -0600 Subject: [PATCH 4/5] dependnecy updates --- requirements.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 834560b..8565257 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,3 @@ Bootstrap-Flask==2.0.0 Flask==2.0.2 Flask-Testing==0.8.1 Flask-WTF==1.0.0 -redis==4.1.1 -rq==1.10.1 From 3edaffaa47cbbace0e9864ea8accfadb97198b4b Mon Sep 17 00:00:00 2001 From: Marc Date: Sat, 28 Jan 2023 00:13:18 +0100 Subject: [PATCH 5/5] aaa --- docker-compose.yml | 15 +++++++++++++++ manage.py | 11 ++++++++++- project/server/config.py | 2 ++ project/server/main/tasks.py | 9 +++++++++ project/server/main/views.py | 17 +++++++++++++++-- requirements.txt | 2 ++ 6 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 project/server/main/tasks.py diff --git a/docker-compose.yml b/docker-compose.yml index b4cd93c..6398830 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,3 +14,18 @@ services: environment: - FLASK_DEBUG=1 - APP_SETTINGS=project.server.config.DevelopmentConfig + depends_on: + - redis + + worker: + image: web + command: python manage.py run_worker + volumes: + - .:/usr/src/app + environment: + - APP_SETTINGS=project.server.config.DevelopmentConfig + depends_on: + - redis + + redis: + image: redis:6.2-alpine \ No newline at end of file diff --git a/manage.py b/manage.py index f395c01..4ca2b0f 100644 --- a/manage.py +++ b/manage.py @@ -1,5 +1,6 @@ # manage.py - +import redis +from rq import Connection, Worker import unittest @@ -21,6 +22,14 @@ def test(): return 0 return 1 +@cli.command("run_worker") +def run_worker(): + redis_url = app.config["REDIS_URL"] + redis_connection = redis.from_url(redis_url) + with Connection(redis_connection): + worker = Worker(app.config["QUEUES"]) + worker.work() + if __name__ == "__main__": cli() diff --git a/project/server/config.py b/project/server/config.py index 5ef9d9a..0ae95aa 100644 --- a/project/server/config.py +++ b/project/server/config.py @@ -9,6 +9,8 @@ class BaseConfig(object): """Base configuration.""" WTF_CSRF_ENABLED = True + REDIS_URL = "redis://redis:6379/0" + QUEUES = ["default"] class DevelopmentConfig(BaseConfig): diff --git a/project/server/main/tasks.py b/project/server/main/tasks.py new file mode 100644 index 0000000..80faf77 --- /dev/null +++ b/project/server/main/tasks.py @@ -0,0 +1,9 @@ +# project/server/main/tasks.py + + +import time + + +def create_task(task_type): + time.sleep(int(task_type) * 10) + return True \ No newline at end of file diff --git a/project/server/main/views.py b/project/server/main/views.py index 365c6c1..5aee977 100644 --- a/project/server/main/views.py +++ b/project/server/main/views.py @@ -1,7 +1,11 @@ # project/server/main/views.py +import redis +from rq import Queue, Connection -from flask import render_template, Blueprint, jsonify, request +from flask import render_template, Blueprint, jsonify, request, current_app + +from project.server.main.tasks import create_task main_blueprint = Blueprint("main", __name__,) @@ -14,7 +18,16 @@ def home(): @main_blueprint.route("/tasks", methods=["POST"]) def run_task(): task_type = request.form["type"] - return jsonify(task_type), 202 + with Connection(redis.from_url(current_app.config["REDIS_URL"])): + q = Queue() + task = q.enqueue(create_task, task_type) + response_object = { + "status": "success", + "data": { + "task_id": task.get_id() + } + } + return jsonify(response_object), 202 @main_blueprint.route("/tasks/", methods=["GET"]) diff --git a/requirements.txt b/requirements.txt index 8565257..580e5ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,5 @@ Bootstrap-Flask==2.0.0 Flask==2.0.2 Flask-Testing==0.8.1 Flask-WTF==1.0.0 +redis==4.1.1 +rq==1.10.1 \ No newline at end of file