parent
a95983aab6
commit
17d495c73a
Binary file not shown.
Binary file not shown.
@ -0,0 +1,30 @@
|
||||
import mysql.connector
|
||||
from AiService.Config.Config import *
|
||||
|
||||
class TaskModel:
|
||||
def __init__(self):
|
||||
# 初始化 MySQL 连接
|
||||
self.connection = mysql.connector.connect(**MYSQL_CONFIG)
|
||||
self.cursor = self.connection.cursor()
|
||||
|
||||
def insert_task(self, task_id: str, keyword: str):
|
||||
"""
|
||||
插入任务记录到 t_gen_tasks 表
|
||||
"""
|
||||
try:
|
||||
query = """
|
||||
INSERT INTO t_gen_tasks (task_id, keyword, status)
|
||||
VALUES (%s, %s, %s)
|
||||
"""
|
||||
self.cursor.execute(query, (task_id, keyword, 'pending'))
|
||||
self.connection.commit()
|
||||
except Exception as e:
|
||||
print(f"Failed to insert task: {str(e)}")
|
||||
raise
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
关闭 MySQL 连接
|
||||
"""
|
||||
self.cursor.close()
|
||||
self.connection.close()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue