diff --git a/.python-version b/.python-version
index 1981190..7b59a5c 100644
--- a/.python-version
+++ b/.python-version
@@ -1 +1 @@
-3.8.0
+3.10.2
diff --git a/Dockerfile b/Dockerfile
index c5b4822..045e057 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,5 @@
# base image
-FROM python:3.8.0-alpine
+FROM python:3.10-alpine
# set working directory
RUN mkdir -p /usr/src/app
diff --git a/LICENSE b/LICENSE
index a59e7e6..b3f8034 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2019 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/docker-compose.yml b/docker-compose.yml
index 5b479bf..6398830 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,4 +1,4 @@
-version: '3.7'
+version: '3.8'
services:
@@ -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/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/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/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 d90a786..580e5ad 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,6 @@
-Flask==1.1.1
-Flask-Bootstrap==3.3.7.1
-Flask-Testing==0.7.1
-Flask-WTF==0.14.2
+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