|
|
|
@ -4,6 +4,7 @@ from multiprocessing import cpu_count |
|
|
|
|
from update.models import Cinema |
|
|
|
|
import queue |
|
|
|
|
import threading |
|
|
|
|
from django.utils import timezone |
|
|
|
|
import datetime |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -30,19 +31,19 @@ class GetVersion(object): |
|
|
|
|
cpu_num = cpu_count() - 1 if cpu_count() > 1 else 1 |
|
|
|
|
cinema_num = len(all_cinema_obj) |
|
|
|
|
self.th_num = cpu_num if cpu_num < cinema_num else cinema_num |
|
|
|
|
print(self.queue) |
|
|
|
|
|
|
|
|
|
def main_process(self): |
|
|
|
|
print('main_process') |
|
|
|
|
self.get_all_cinema() |
|
|
|
|
threads = [] |
|
|
|
|
for i in range(self.th_num): |
|
|
|
|
t = threading.Thread(target=self.get_cinema_ver, args=(self.queue,)) |
|
|
|
|
threads.append(t) |
|
|
|
|
for i in range(self.th_num): |
|
|
|
|
threads[i].start() |
|
|
|
|
for i in range(self.th_num): |
|
|
|
|
threads[i].join() |
|
|
|
|
while self.queue.qsize() > 0: |
|
|
|
|
threads = [] |
|
|
|
|
for i in range(self.th_num): |
|
|
|
|
t = threading.Thread(target=self.get_cinema_ver, args=(self.queue,)) |
|
|
|
|
threads.append(t) |
|
|
|
|
for i in range(self.th_num): |
|
|
|
|
threads[i].start() |
|
|
|
|
for i in range(self.th_num): |
|
|
|
|
threads[i].join() |
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
|
|
def get_cinema_ver(q): |
|
|
|
@ -51,7 +52,6 @@ class GetVersion(object): |
|
|
|
|
return |
|
|
|
|
else: |
|
|
|
|
cinema_config = q.get() |
|
|
|
|
print(cinema_config) |
|
|
|
|
sql_str = "SELECT * FROM cinema_version;" |
|
|
|
|
ip = cinema_config.get('ip') |
|
|
|
|
db_config = { |
|
|
|
@ -61,18 +61,17 @@ class GetVersion(object): |
|
|
|
|
'database': 'cine', |
|
|
|
|
'connect_timeout': 5, |
|
|
|
|
} |
|
|
|
|
print(db_config) |
|
|
|
|
db_conn = pymysql.Connect(**db_config) |
|
|
|
|
db_cursor = db_conn.cursor(cursor=DictCursor) |
|
|
|
|
db_cursor.execute(sql_str) |
|
|
|
|
res = db_cursor.fetchone() |
|
|
|
|
print(res) |
|
|
|
|
update_data = { |
|
|
|
|
'sys_ver': res['server_version'], |
|
|
|
|
'client_ver': res['client_version'], |
|
|
|
|
'update_time': datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') |
|
|
|
|
# 'update_time': datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S') |
|
|
|
|
'update_time': timezone.now() |
|
|
|
|
} |
|
|
|
|
print(update_data) |
|
|
|
|
print(ip, update_data, db_config) |
|
|
|
|
cinema_obj = Cinema.objects.filter(ip=ip).update(**update_data) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|