Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cyhy_commander/commander.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,20 @@ def do_work(self):
),
)

# clear out retrieved but unprocessed work
self.__logger.debug("Process any leftover local jobs")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer this verbiage to "leftover", but feel free to ignore:

Suggested change
self.__logger.debug("Process any leftover local jobs")
self.__logger.debug("Process any previously-unprocessed local jobs")

self.__queue_monitor_output_lock.release()
for target_dir, target_queue in (
(SUCCESS_DIR, self.__successful_job_queue),
(FAILED_DIR, self.__failed_job_queue),
):
for job in os.listdir(target_dir):
target_queue.put(os.path.join(target_dir, job))
Comment on lines +770 to +771
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

Missing error handling for os.listdir() and file system operations. If there are permission issues or if the directory is temporarily unavailable, this code will crash during startup. Consider wrapping this section in a try-except block to log errors gracefully and continue startup even if leftover jobs cannot be processed.

Additionally, os.listdir() returns all entries in the directory including hidden files (e.g., .DS_Store, temporary files) and potentially non-directory entries. Consider filtering the results to only include valid job directories using os.path.isdir() to avoid processing invalid entries that could cause errors downstream.

Suggested change
for job in os.listdir(target_dir):
target_queue.put(os.path.join(target_dir, job))
try:
for job in os.listdir(target_dir):
job_path = os.path.join(target_dir, job)
if os.path.isdir(job_path):
target_queue.put(job_path)
except Exception as e:
self.__logger.error(
"Error processing leftover jobs in directory '%s': %s", target_dir, e
)
self.__logger.error(traceback.format_exc())

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@jsf9k jsf9k Nov 14, 2025

Choose a reason for hiding this comment

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

Adding error handling is a good idea, even if only so we can output a more specific logging message before re-throwing the exception, but I'll leave it up to you to decide if it's worth it here. If not, please add an issue so we don't forget to revisit this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Aside from the error handling what are your thoughts on only processing directories or some other kind of filtration for entries in the target directories?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we don't filter directory names when processing them normally, I don't think we need to do it here. If we do, then we should filter similarly here. Not a bad idea to add a TODO issue to filter in both places though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We do not filter normally, but we also do not iterate over directory contents normally. The normal operation would simply ignore any directories that the commander itself did not put into the two directories while it is running.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then it's probably safest to filter so that we only process directories that match our expected pattern.

self.__successful_job_queue.join()
self.__failed_job_queue.join()
self.__queue_monitor_output_lock.acquire()
self.__logger.debug("Finished processing leftover jobs")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To match verbiage in my other suggestion:

Suggested change
self.__logger.debug("Finished processing leftover jobs")
self.__logger.debug("Finished processing previously-unprocessed jobs")


# main work loop
while self.__is_running:
try:
Expand Down
Loading