Browse Source

update_published_articles_read_detail
v2

luojunhui 3 months ago
parent
commit
23c9cd7c94

+ 9 - 0
run_update_articles_from_aigc_system.py

@@ -0,0 +1,9 @@
+"""
+@author: luojunhui
+"""
+from tasks.update_article_info_from_aigc import UpdateArticleInfoFromAIGC
+
+
+if __name__ == "__main__":
+    update_article_info_from_aigc = UpdateArticleInfoFromAIGC()
+    update_article_info_from_aigc.deal()

+ 26 - 0
sh/run_update_article_info_from_aigc.sh

@@ -0,0 +1,26 @@
+#!/bin/bash
+
+# 获取当前日期,格式为 YYYY-MM-DD
+CURRENT_DATE=$(date +%F)
+
+# 日志文件路径,包含日期
+LOG_FILE="/root/luojunhui/logs/update_article_info_from_aigc_task_log_$CURRENT_DATE.txt"
+
+# 重定向整个脚本的输出到带日期的日志文件
+exec >> "$LOG_FILE" 2>&1
+if pgrep -f "python3 run_update_articles_from_aigc_system.py" > /dev/null
+then
+    echo "$(date '+%Y-%m-%d %H:%M:%S') - run_update_articles_from_aigc_system.py is running"
+else
+    echo "$(date '+%Y-%m-%d %H:%M:%S') - trying to restart run_update_articles_from_aigc_system.py"
+    # 切换到指定目录
+    cd /root/luojunhui/LongArticlesJob
+
+    # 激活 Conda 环境
+    source /root/miniconda3/etc/profile.d/conda.sh
+    conda activate tasks
+
+    # 在后台运行 Python 脚本并重定向日志输出
+    nohup python3 run_update_articles_from_aigc_system.py >> "${LOG_FILE}" 2>&1 &
+    echo "$(date '+%Y-%m-%d %H:%M:%S') - successfully restarted run_update_articles_from_aigc_system.py"
+fi

+ 2 - 6
tasks/update_article_info_from_aigc.py

@@ -42,7 +42,7 @@ class UpdateArticleInfoFromAIGC(object):
         sql = f"""
             SELECT trace_id, push_type
             FROM long_articles_published_trace_id
-            WHERE create_timestamp> UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AND status = {const.INIT_STATUS};
+            WHERE create_timestamp > UNIX_TIMESTAMP(DATE_SUB(CURDATE(), INTERVAL 1 DAY)) AND status = {const.INIT_STATUS};
         """
         article_list = self.long_articles_db_client.fetch(sql, cursor_type=DictCursor)
         return article_list
@@ -206,6 +206,7 @@ class UpdateArticleInfoFromAIGC(object):
         main function
         """
         article_list = self.get_published_articles()
+
         for article in tqdm(article_list, desc="更新文章信息"):
             try:
                 self.update_each_article(article)
@@ -213,8 +214,3 @@ class UpdateArticleInfoFromAIGC(object):
                 print(e)
 
 
-if __name__ == "__main__":
-    u = UpdateArticleInfoFromAIGC()
-    u.deal()
-
-