程序优化

This commit is contained in:
dongchangxi committed 2023-11-20 10:53:38 +08:00
1 parent 2093ff5526
commit 10640a63c2
8 files changed
+260 -44

No files matched your search

+4 -4
View File
@@ -18,7 +18,7 @@ def get_task(task_type):
with pymysqlAlias() as conn:
cursor = conn.cursor()
sql = f'select task_key from tasks where task_type = "{task_type}" and status = 0 order by priority desc, id asc limit 1'
sql = f'select task_key from tasks where status = 0 order by priority desc, id asc limit 1'
# print(f'sql: {sql}')
cursor.execute(sql)
data = cursor.fetchone()
@@ -40,7 +40,7 @@ def add_task(data):
if data["psid"] == '85':
sql = f'insert into tasks (task_type, task_key,studio_id) values ("{data["task_type"]}", "{data["task_key"]}","{data["psid"]}")'
else:
sql = f'insert into tasks (task_type, task_key, priority,studio_id) values ("{data["task_type"]}", "{data["task_key"]}", 1,"{data["psid"]}")'
sql = f'insert into tasks (task_type, task_key, priority,studio_id) values ("{data["task_type"]}", "{data["task_key"]}", {data["priority"]},"{data["psid"]}")'
# print(f'sql: {sql}')
cursor.execute(sql)
conn.commit()
@@ -66,7 +66,7 @@ def start_task(data):
cursor = conn.cursor()
hostname = socket.gethostname()
sql = f'update tasks set status = 1, hostname = "{hostname}", started_at = now(), updated_at = now() where task_type = "{data["task_type"]}" and task_key = "{data["task_key"]}"'
sql = f'update tasks set status = 1, hostname = "{hostname}", started_at = now(), updated_at = now() where task_key = "{data["task_key"]} and status = 0"'
# print(f'sql: {sql}')
cursor.execute(sql)
conn.commit()
@@ -80,7 +80,7 @@ def finish_task(data):
cursor = conn.cursor()
hostname = socket.gethostname()
sql = f'update tasks set status = 2, hostname = "{hostname}", finished_at = now(), updated_at = now() where task_type = "{data["task_type"]}" and task_key = "{data["task_key"]}"'
sql = f'update tasks set status = 2, hostname = "{hostname}", finished_at = now(), updated_at = now() where status = 1 and task_key = "{data["task_key"]}" '
# print(f'sql: {sql}')
cursor.execute(sql)
conn.commit()