Commit 4e2fc3df150cce5bda1ea64528eafb3d9218f724
1 parent
816cb7e5
Exists in
devel
[TranslationServer] Atualiza o BD em nova thread
Showing
1 changed file
with
15 additions
and
9 deletions
Show diff stats
src/TranslationServer.py
... | ... | @@ -5,11 +5,13 @@ from flask import Flask, request, send_file, abort |
5 | 5 | from functools import wraps |
6 | 6 | from PortGlosa import traduzir |
7 | 7 | from subprocess import check_output |
8 | -import os, argparse | |
8 | +from threading import Lock | |
9 | +import os, argparse, thread | |
9 | 10 | |
10 | 11 | RUN_MODE=None |
11 | 12 | BUNDLES_PATH=None |
12 | 13 | conn=None |
14 | +lock = Lock() | |
13 | 15 | app=Flask(__name__, static_url_path="", static_folder="/var/www/") |
14 | 16 | |
15 | 17 | def check_run_mode(func): |
... | ... | @@ -101,18 +103,22 @@ def update_platform_db(platform_name): |
101 | 103 | cursor.execute(query_string, (platform_name)); |
102 | 104 | conn.commit() |
103 | 105 | |
106 | +def update_statistic(sign_name, sign_type, file_exists): | |
107 | + if RUN_MODE == "full": | |
108 | + with lock: | |
109 | + has = "YES" if file_exists else "NO" | |
110 | + value_sign_name = select_sign_db(sign_name) | |
111 | + if value_sign_name is None: | |
112 | + insert_sign_db(sign_name, 1, has) | |
113 | + else: | |
114 | + update_sign_db(sign_name, value_sign_name+1, has) | |
115 | + update_platform_db(sign_type) | |
116 | + | |
104 | 117 | def check_sign(sign_name, sign_type): |
105 | 118 | if " " in sign_name or sign_type not in BUNDLES_PATH: abort(400) |
106 | 119 | bundle_path = os.path.join(BUNDLES_PATH[sign_type], sign_name) |
107 | 120 | file_exists = os.path.exists(bundle_path) |
108 | - if RUN_MODE == "full": | |
109 | - has = "YES" if file_exists else "NO" | |
110 | - value_sign_name = select_sign_db(sign_name) | |
111 | - if value_sign_name is None: | |
112 | - insert_sign_db(sign_name, 1, has) | |
113 | - else: | |
114 | - update_sign_db(sign_name, value_sign_name+1, has) | |
115 | - update_platform_db(sign_type) | |
121 | + thread.start_new_thread(update_statistic, (sign_name, sign_type, file_exists)) | |
116 | 122 | if file_exists: |
117 | 123 | return send_file(bundle_path, as_attachment=True) |
118 | 124 | abort(404) | ... | ... |