Skip to content

Commit

Permalink
Add error handling for None values and fix type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
glrs committed Oct 7, 2024
1 parent 2dadf74 commit dec53e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/couchdb/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ async def get_changes(
try:
doc = self.db.get(change["id"])
last_processed_seq = change["seq"]
Ygg.save_last_processed_seq(last_processed_seq)
if last_processed_seq is not None:
Ygg.save_last_processed_seq(last_processed_seq)
else:
logging.warning(
"Received `None` for last_processed_seq. Skipping save."
)

yield doc
except Exception as e:
logging.warning(f"Error processing change: {e}")
Expand Down
14 changes: 10 additions & 4 deletions lib/module_utils/sjob_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
import re
import subprocess
from typing import Any, Optional
from pathlib import Path
from typing import Any, Optional, Union

from lib.core_utils.config_loader import configs
from lib.core_utils.logging_utils import custom_logger
Expand Down Expand Up @@ -143,16 +144,21 @@ def __init__(
)
self.command_timeout: float = command_timeout

async def submit_job(self, script_path: str) -> Optional[str]:
async def submit_job(self, script_path: Union[str, Path]) -> Optional[str]:
"""Submit a Slurm job using the specified script.
Args:
script_path (str): Path to the Slurm script.
script_path (Union[str, Path]): Path to the Slurm script.
Returns:
Optional[str]: The job ID if submission is successful, None otherwise.
"""
sbatch_command = ["sbatch", script_path]
sbatch_command = ["sbatch", str(script_path)]

if not Path(script_path).is_file():
logging.error(f"Script file does not exist: {script_path}")
return None

try:
process = await asyncio.create_subprocess_exec(
*sbatch_command,
Expand Down

0 comments on commit dec53e1

Please sign in to comment.