[fix] Adds a worker

This commit is contained in:
alban 2020-10-22 21:16:30 +02:00
parent b31f725d04
commit dcdccb57e2
2 changed files with 15 additions and 2 deletions

View File

@ -26,7 +26,6 @@ services:
assets:
env_file: .env
build: .
image: teamlaser/laser-app:latest
ports:
- "8080:80"
@ -34,3 +33,11 @@ services:
- app
command: nginx -g 'daemon off;error_log /dev/stdout info;'
worker:
env_file: .env
build: .
image: teamlaser/laser-app:latest
depends_on:
- db
command: bash -c "while true; do python ./worker.py; sleep 30; done"

View File

@ -5,12 +5,17 @@ from PIL import Image
from redis import Redis
import base64
import json
import os
import potrace
import re
import time
color = 65280
r = Redis()
environ = os.environ
host = environ['DB_HOST'] if 'DB_HOST' in os.environ else "localhost"
port = environ['DB_PORT'] if 'DB_PORT' in os.environ else 6379
r = Redis(host="db", port=port)
def convertImg(src, image_path="/tmp/"):
base64_data = re.sub('^data:image/.+;base64,', '', src)
@ -57,6 +62,7 @@ while data :
item["points_list"] = pl
item["created_at"] = time.time()
r.hset("images",hash_name, json.dumps(item))
print("Handled image {}".format(hash_name))
data = r.lpop('image-convert')
except Exception as e: