add new system_activity.json for rate limit X posts
This commit is contained in:
+9
-17
@@ -37,6 +37,7 @@ import fcntl
|
||||
load_dotenv()
|
||||
|
||||
is_posting = False
|
||||
SCRIPT_NAME = "foodie_automator_rss"
|
||||
LOCK_FILE = "/home/shane/foodie_automator/locks/foodie_automator_rss.lock"
|
||||
LOG_FILE = "/home/shane/foodie_automator/logs/foodie_automator_rss.log"
|
||||
LOG_PRUNE_DAYS = 30
|
||||
@@ -131,12 +132,9 @@ def acquire_lock():
|
||||
sys.exit(0)
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
logging.info("Received termination signal, checking if safe to exit...")
|
||||
if is_posting:
|
||||
logging.info("Currently posting, will exit after completion.")
|
||||
else:
|
||||
logging.info("Safe to exit immediately.")
|
||||
sys.exit(0)
|
||||
logging.info("Received termination signal, marking script as stopped...")
|
||||
update_system_activity(SCRIPT_NAME, "stopped")
|
||||
sys.exit(0)
|
||||
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
@@ -454,20 +452,14 @@ def run_rss_automator():
|
||||
lock_fd = None
|
||||
try:
|
||||
lock_fd = acquire_lock()
|
||||
update_system_activity(SCRIPT_NAME, "running", os.getpid()) # Record start
|
||||
logging.info("***** RSS Automator Launched *****")
|
||||
# Load JSON files once
|
||||
posted_titles_data = load_json_file(POSTED_TITLES_FILE, EXPIRATION_HOURS)
|
||||
posted_titles = set(entry["title"] for entry in posted_titles_data)
|
||||
used_images_data = load_json_file(USED_IMAGES_FILE, IMAGE_EXPIRATION_DAYS)
|
||||
used_images = set(entry["title"] for entry in used_images_data if "title" in entry)
|
||||
post_data, category, sleep_time = curate_from_rss(posted_titles_data, posted_titles, used_images_data, used_images)
|
||||
if not post_data:
|
||||
logging.info("No postable RSS article found")
|
||||
logging.info(f"Completed run with sleep time: {sleep_time} seconds")
|
||||
time.sleep(sleep_time)
|
||||
return post_data, category, sleep_time # Fixed return to include sleep_time
|
||||
# ... (rest of the function) ...
|
||||
update_system_activity(SCRIPT_NAME, "stopped") # Record stop
|
||||
return post_data, category, sleep_time
|
||||
except Exception as e:
|
||||
logging.error(f"Fatal error in run_rss_automator: {e}", exc_info=True)
|
||||
update_system_activity(SCRIPT_NAME, "stopped") # Record stop on error
|
||||
return None, None, random.randint(600, 1800)
|
||||
finally:
|
||||
if lock_fd:
|
||||
|
||||
Reference in New Issue
Block a user