Skip to content

Commit fb3e09e

Browse files
committed
updated notification setting to include feed details
1 parent 79c3e3d commit fb3e09e

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

notification.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,50 @@ def post_request(self, endpoint: str, **kwargs):
4242
except ValueError:
4343
return response.text
4444

45+
def get_feed_id_from_plugin_inst(self, plugin_inst: int) -> int:
46+
"""Get feed_id from a given plugin instance"""
47+
logger.info(f"Fetching feed id for plugin instance with ID: {plugin_inst}")
48+
response = self.make_request("GET",f"/plugins/instances/{plugin_inst}/")
49+
for item in response:
50+
for field in item.get("data", []):
51+
if field.get("name") == "feed_id":
52+
return field.get("value")
53+
return -1
54+
55+
def get_feed_details_from_id(self, feed_id: int) -> dict:
56+
"""Get feed details given a feed id"""
57+
feed_details = {}
58+
59+
logger.info(f"Getting feed details for ID: {feed_id}")
60+
response = self.make_request("GET",f"/{feed_id}/")
61+
for item in response:
62+
for field in item.get("data", []):
63+
if field.get("name") == "creation_date":
64+
feed_details["date"] = field.get("value")
65+
if field.get("name") == "name":
66+
feed_details["name"] = field.get("value")
67+
if field.get("name") == "owner_username":
68+
feed_details["owner"] = field.get("value")
69+
70+
return feed_details
71+
4572
def run_notification_plugin(self, pv_id: int, msg: str, rcpts: str, smtp: str, search_data: str) -> int:
4673
"""
4774
Run the pl-notification plugin.
4875
"""
49-
email_content = f"Your workflow is now complete. Kindly login to ChRIS for detailed logs."
76+
feed_id = self.get_feed_id_from_plugin_inst(pv_id)
77+
feed_details = self.get_feed_details_from_id(feed_id)
78+
email_content = (f"Your workflow is now complete."
79+
f"\nFeed Name: {feed_details['name']}"
80+
f"\nDate: {feed_details['date']}"
81+
f"\n\nKindly login to ChRIS as *{feed_details['owner']}* to access the logs for more details.")
5082

5183
try:
5284
plugin_id = self.get_plugin_id({"name": "pl-notification", "version": "0.1.0"})
5385
instance_id = self.create_plugin_instance(plugin_id, {
5486
"previous_id": pv_id,
5587
"content": email_content,
56-
"title": msg,
88+
"title": f"Analysis {feed_details['name']} is complete.",
5789
"rcpt": rcpts,
5890
"sender": "noreply@fnndsc.org",
5991
"mail_server": smtp

0 commit comments

Comments
 (0)