offline_dict_lock = Lock()
def schedule_host_deletion(hostname, offline_dict, update_signal, settings_widget, lock, main_window):
    def delete_host():
        normalized_hostname = hostname.upper()
        with lock:
            if normalized_hostname in offline_dict:
                store_name = offline_dict[normalized_hostname]['store_name']
                log_online(
                    hostname,
                    store_name,
                    offline_dict,
                    normalized_hostname,
                    offline_dict[normalized_hostname]['inspect_status']
                )
                offline_duration = time.time() - offline_dict[normalized_hostname]['start_time']

                if settings_widget.sound_alert_enabled and offline_duration > OFFLINE_DURATION and len(main_window.sound_manager.sound_queue) < main_window.sound_manager.max_sounds:
                    hostname_lower = hostname.lower()
                    if any(fnmatch.fnmatch(hostname_lower, pattern.lower()) for pattern in settings_widget.sound_alert_patterns):
                        if hasattr(main_window, 'sound_manager'):
                            message = f"Big C {store_name} return to Online"
                            audio_filename = f"{message}.mp3"
                            audio_path = os.path.join('sounds', audio_filename)
                            fallback_sound_file = "returnonline.mp3"

                            def play_sound():
                                if os.path.exists(audio_path):
                                    main_window.sound_manager.play(audio_path)
                                else:
                                    print(f"Sound file '{audio_filename}' does not exist. Attempting to download...")
                                    downloaded_file = download_audio(message)
                                    if downloaded_file and os.path.exists(downloaded_file):
                                        main_window.sound_manager.play(downloaded_file)
                                    else:
                                        if os.path.exists(fallback_sound_file):
                                            print(f"Failed to download. Playing fallback sound file: {fallback_sound_file}")
                                            main_window.sound_manager.play(fallback_sound_file)
                                        else:
                                            print("Failed to download sound file and no fallback sound available.")

                            sound_thread = threading.Thread(target=play_sound)
                            sound_thread.start()

                del offline_dict[normalized_hostname]
                save_offline_state('offline_state.json', offline_dict)

                if normalized_hostname in settings_widget.exception_hosts:
                    settings_widget.exception_hosts.remove(normalized_hostname)
                    settings_widget.update_exception_hosts_signal.emit(settings_widget.exception_hosts)
            #else:
                #print(f"Hostname {normalized_hostname} was not in offline_dict")

        update_signal.emit()

    timer = threading.Timer(TIME_BEFORE_ONLINE, delete_host)
    timer.start()

ให้เล่นเสียงทันทีที่พบว่า host online และลบ host ออกตามเวลาที่กำหนด