Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable job emails #60

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions bfabric/bfabric.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,7 @@ def compose_bash_script(self, configuration=None, configuration_parser=lambda x:
set -e
set -o pipefail

## TODO: #59
export EMAIL="[email protected] [email protected]"
export EMAIL="{job_notification_emails}"
export EXTERNALJOB_ID={3}
export RESSOURCEID_OUTPUT={4}
export RESSOURCEID_STDOUT_STDERR="{5} {6}"
Expand Down Expand Up @@ -734,7 +733,8 @@ def compose_bash_script(self, configuration=None, configuration_parser=lambda x:
config['job_configuration']['executable'],
config['job_configuration']['workunit_id'],
self.nodelist,
self.memory)
self.memory,
job_notification_emails=self.B.config.job_notification_emails)

return _cmd_template

Expand Down
17 changes: 12 additions & 5 deletions bfabric/bfabric_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ class BfabricConfig:
password: The web service password (i.e. not the regular user password)
base_url (optional): The API base url
application_ids (optional): Map of application names to ids.
job_notification_emails (optional): Space-separated list of email addresses to notify when a job finishes.
"""

def __init__(
self,
login: str,
password: str,
base_url: str = None,
application_ids: Dict[str, int] = None,
base_url: Optional[str] = None,
application_ids: Optional[Dict[str, int]] = None,
job_notification_emails: Optional[str] = None,
):
self.login = login
self.password = password
self.base_url = base_url or "https://fgcz-bfabric.uzh.ch/bfabric"
self.application_ids = application_ids or {}
self.job_notification_emails = job_notification_emails or ""

def with_overrides(
self,
Expand Down Expand Up @@ -59,7 +62,7 @@ def read_bfabricrc_py(cls, file: io.FileIO) -> BfabricConfig:
continue

key, _, value = [part.strip() for part in line.partition("=")]
if key not in ["_PASSWD", "_LOGIN", "_WEBBASE", "_APPLICATION"]:
if key not in ["_PASSWD", "_LOGIN", "_WEBBASE", "_APPLICATION", "_JOB_NOTIFICATION_EMAILS"]:
continue

# In case of multiple definitions, the first rule counts!
Expand All @@ -82,10 +85,14 @@ def read_bfabricrc_py(cls, file: io.FileIO) -> BfabricConfig:
password=values.get("_PASSWD"),
base_url=values.get("_WEBBASE"),
application_ids=values.get("_APPLICATION"),
job_notification_emails=values.get("_JOB_NOTIFICATION_EMAILS"),
)

def __repr__(self):
return (
f"BfabricConfig(login={repr(self.login)}, password=..., base_url={repr(self.base_url)}, "
f"application_ids={repr(self.application_ids)})"
f"BfabricConfig(login={repr(self.login)}, "
f"password=..., "
f"base_url={repr(self.base_url)}, "
f"application_ids={repr(self.application_ids)}, "
f"job_notification_emails={repr(self.job_notification_emails)})"
)
6 changes: 5 additions & 1 deletion bfabric/tests/unit/test_bfabric_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_read_bfabricrc_py(self):
"# Another comment\n"
"""_WEBBASE = "url"\n"""
"""_APPLICATION = {"app": 1}\n"""
"""_JOB_NOTIFICATION_EMAILS = "email1 email2"\n"""
)
file = io.StringIO(input_text)
setattr(file, "name", "/file")
Expand All @@ -60,6 +61,7 @@ def test_read_bfabricrc_py(self):
self.assertEqual("user", config.password)
self.assertEqual("url", config.base_url)
self.assertEqual({"app": 1}, config.application_ids)
self.assertEqual("email1 email2", config.job_notification_emails)
self.assertEqual(
[
"INFO:bfabric.bfabric_config.BfabricConfig:Reading configuration from: /file"
Expand All @@ -77,11 +79,13 @@ def test_read_bfabricrc_py_when_empty(self):
self.assertIsNone(config.password)
self.assertEqual("https://fgcz-bfabric.uzh.ch/bfabric", config.base_url)
self.assertEqual({}, config.application_ids)
self.assertEqual("", config.job_notification_emails)

def test_repr(self):
rep = repr(self.config)
self.assertEqual(
"BfabricConfig(login='login', password=..., base_url='url', application_ids={'app': 1})",
"BfabricConfig(login='login', password=..., base_url='url', application_ids={'app': 1}, "
"job_notification_emails='')",
rep,
)

Expand Down
Loading