Skip to content

Commit

Permalink
Auto-triggering deduplication: handle more status messages (#256)
Browse files Browse the repository at this point in the history
* handle existing requests' status messages before when deduplicating
* fixed the code to grab Fritz's error/warning messages
  • Loading branch information
Theodlz authored Oct 6, 2023
1 parent c30336f commit bd045a6
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions kowalski/alert_brokers/alert_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,12 @@ def alert_sentinel_skyportal(self, alert, prv_candidates, passed_filters):
existing_requests = [
r
for r in existing_requests
if r["status"] in ["completed", "submitted", "deleted"]
if any(
[
status in str(r["status"]).lower()
for status in ["complete", "submitted", "deleted"]
]
)
]
# sort by priority (highest first)
existing_requests = sorted(
Expand All @@ -1894,7 +1899,7 @@ def alert_sentinel_skyportal(self, alert, prv_candidates, passed_filters):
== passed_filter["auto_followup"]["data"]["allocation_id"]
and not set(
passed_filter["auto_followup"]["data"]["target_group_ids"]
).isdisjoint(set([g["id"] for g in r["target_groups"]]))
).isdisjoint(set([g["id"] for g in r.get("target_groups", [])]))
and compare_dicts(
passed_filter["auto_followup"]["data"]["payload"],
r["payload"],
Expand Down Expand Up @@ -1970,7 +1975,9 @@ def alert_sentinel_skyportal(self, alert, prv_candidates, passed_filters):
)
if response.json()["status"] != "success":
raise ValueError(
response.json().get(
response.json()
.get("data", {})
.get(
"message",
"unknow error posting comment",
)
Expand All @@ -1980,12 +1987,16 @@ def alert_sentinel_skyportal(self, alert, prv_candidates, passed_filters):
f"Failed to post followup comment {comment['text']} for {alert['objectId']} to SkyPortal: {e}"
)
else:
raise ValueError(
response.json().get(
error_message = response.json().get(
"message",
response.json()
.get("data", {})
.get(
"message",
"unknow error posting followup request",
)
),
)
raise ValueError(error_message)
except Exception as e:
log(
f"Failed to post followup request for {alert['objectId']} to SkyPortal: {e}"
Expand All @@ -1995,17 +2006,22 @@ def alert_sentinel_skyportal(self, alert, prv_candidates, passed_filters):
# update the existing request with the new priority
request_to_update = existing_requests_filtered[0][1]
# if the status is completed or deleted, do not update
if request_to_update["status"] in ["completed", "deleted"]:
if any(
[
status in str(request_to_update["status"]).lower()
for status in ["complete", "deleted"]
]
):
log(
f"Followup request for {alert['objectId']} and allocation_id {passed_filter['auto_followup']['allocation_id']} already exists on SkyPortal, but is completed or deleted, no need for update"
)
# if the status is submitted, and the new priority is higher, update
if (
request_to_update["status"] == "submitted"
and passed_filter["auto_followup"]["data"]["payload"][
"priority"
]
> request_to_update["payload"]["priority"]
if "submitted" in str(
request_to_update["status"]
).lower() and float(
passed_filter["auto_followup"]["data"]["payload"]["priority"]
) > float(
request_to_update["payload"]["priority"]
):
with timer(
f"Updating priority of auto followup request for {alert['objectId']} to SkyPortal",
Expand Down

0 comments on commit bd045a6

Please sign in to comment.