[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: assets:
env_file: .env env_file: .env
build: .
image: teamlaser/laser-app:latest image: teamlaser/laser-app:latest
ports: ports:
- "8080:80" - "8080:80"
@ -34,3 +33,11 @@ services:
- app - app
command: nginx -g 'daemon off;error_log /dev/stdout info;' 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 from redis import Redis
import base64 import base64
import json import json
import os
import potrace import potrace
import re import re
import time import time
color = 65280 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/"): def convertImg(src, image_path="/tmp/"):
base64_data = re.sub('^data:image/.+;base64,', '', src) base64_data = re.sub('^data:image/.+;base64,', '', src)
@ -57,6 +62,7 @@ while data :
item["points_list"] = pl item["points_list"] = pl
item["created_at"] = time.time() item["created_at"] = time.time()
r.hset("images",hash_name, json.dumps(item)) r.hset("images",hash_name, json.dumps(item))
print("Handled image {}".format(hash_name))
data = r.lpop('image-convert') data = r.lpop('image-convert')
except Exception as e: except Exception as e: