Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

利用MySQL ON DUPLICATE KEY UPDATE方法解决重复执行一些任务出现IntegrityError错误问题 #139

Closed
wants to merge 2 commits into from

Conversation

dominicx
Copy link
Contributor

@dominicx dominicx commented Dec 9, 2024

selection job如果被执行多次,会出现类似以下错误:
database.insert_other_db_from_df处理异常:cn_stock_selection表(pymysql.err.IntegrityError) (1062, "Duplicate entry '2024-12-17-300071' for key 'PRIMARY'")

使用mysql方法来解决这个问题。

 selection job如果被执行多次,会出现类似以下错误:
database.insert_other_db_from_df处理异常:cn_stock_selection表(pymysql.err.IntegrityError) (1062, "Duplicate entry '2024-12-17-300071' for key 'PRIMARY'")

使用mysql方法来解决这个问题。
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试不过。
C:\Python\Python3\python.exe D:\my\src\py\stock\instock\job\selection_data_daily_job.py
ERROR:root:database.insert_other_db_from_df处理异常:cn_stock_selection表Can't reconnect until invalid transaction is rolled back. Please rollback() fully before proceeding (Background on this error at: https://sqlalche.me/e/20/8s2b)

selection job如果被执行多次,会出现类似以下错误:
database.insert_other_db_from_df处理异常:cn_stock_selection表(pymysql.err.IntegrityError) (1062, "Duplicate entry '2024-12-17-300071' for key 'PRIMARY'")

使用mysql方法来解决这个问题。
并使用with engine.begin()来自动处理transaction,并解决Can't reconnect until invalid transaction is rolled back.
@MontBlancPeter
Copy link

#在selection_data_daily_job.py加一行处理:
def save_nph_stock_selection_data(date, before=True):
if before:
return

try:
    data = stf.fetch_stock_selection()
    data = data.drop_duplicates(subset="code", keep="last")   ##<---新增加去除重复行!

同时第一次运行JOB时老是有如下错误,该如何解决?
stockfetch.stock_hist_cache处理异常:000622代码('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

@myhhub
Copy link
Owner

myhhub commented Dec 13, 2024

数据源重复,数据库不存在重复的,且这样效率低,直接pandas去除。

@myhhub myhhub closed this Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants