#!/bin/bash

# 获取当前日期，格式为 YYYY-MM-DD
CURRENT_DATE=$(date +%F)

# 日志文件路径，包含日期
LOG_FILE="/root/luojunhui/logs/update_published_articles_v2_task_log_$CURRENT_DATE.txt"

# 重定向整个脚本的输出到带日期的日志文件
exec >> "$LOG_FILE" 2>&1
if pgrep -f "python3 update_published_articles_v2.py" > /dev/null
then
    echo "$(date '+%Y-%m-%d %H:%M:%S') - update_published_articles_v2.py is running"
else
    echo "$(date '+%Y-%m-%d %H:%M:%S') - trying to restart update_published_articles_v2.py"
    cd /root/luojunhui/LongArticlesJob
    source /root/miniconda3/etc/profile.d/conda.sh
    conda activate tasks
    nohup python3 update_published_articles_v2.py >> "${LOG_FILE}" 2>&1 &
    echo "$(date '+%Y-%m-%d %H:%M:%S') - successfully restarted update_published_articles_v2.py"
fi