Skip to content

Commit

Permalink
SkyPortal API calls: kwargs (#266)
Browse files Browse the repository at this point in the history
pass a specific timeout as kwargs when running an API call to SkyPortal. This is for us to try to solve some timeout issues when posting large lightcurves.
  • Loading branch information
Theodlz authored Jan 9, 2024
1 parent 4763e77 commit 8c3f89f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
17 changes: 11 additions & 6 deletions kowalski/alert_brokers/alert_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,15 @@ def __init__(self, **kwargs):
)
log("AlertWorker setup complete")

def api_skyportal(self, method: str, endpoint: str, data: Optional[Mapping] = None):
def api_skyportal(
self, method: str, endpoint: str, data: Optional[Mapping] = None, **kwargs
):
"""Make an API call to a SkyPortal instance
:param method:
:param endpoint:
:param data:
:param kwargs:
:return:
"""
method = method.lower()
Expand All @@ -509,13 +512,16 @@ def api_skyportal(self, method: str, endpoint: str, data: Optional[Mapping] = No
if method not in ["head", "get", "post", "put", "patch", "delete"]:
raise ValueError(f"Unsupported method: {method}")

timeout = kwargs.get("timeout", 5)

if method == "get":
response = methods[method](
f"{config['skyportal']['protocol']}://"
f"{config['skyportal']['host']}:{config['skyportal']['port']}"
f"{endpoint}",
params=data,
headers=self.session_headers,
timeout=timeout,
)
else:
response = methods[method](
Expand All @@ -524,6 +530,7 @@ def api_skyportal(self, method: str, endpoint: str, data: Optional[Mapping] = No
f"{endpoint}",
json=data,
headers=self.session_headers,
timeout=timeout,
)

return response
Expand Down Expand Up @@ -1367,11 +1374,9 @@ def alert_filter__user_defined(
if not isinstance(_filter.get("autosave", False), bool):
passed_filter["auto_followup"]["data"][
"ignore_source_group_ids"
] = [
_filter.get("autosave", {}).get(
"ignore_group_ids", []
)
]
] = _filter.get("autosave", {}).get(
"ignore_group_ids", []
)

passed_filters.append(passed_filter)

Expand Down
2 changes: 1 addition & 1 deletion kowalski/alert_brokers/alert_broker_ztf.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def alert_put_photometry(self, alert):
):
try:
response = self.api_skyportal(
"PUT", "/api/photometry", photometry
"PUT", "/api/photometry", photometry, timeout=15
)
if response.json()["status"] == "success":
log(
Expand Down
25 changes: 15 additions & 10 deletions kowalski/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3296,18 +3296,23 @@ async def put(self, request: web.Request) -> web.Response:

# check if the skymap already exists

query = {
"$and": [
{
"$or": [
{"dateobs": dateobs},
{"triggerid": triggerid},
],
},
{"localization_name": skymap["localization_name"]},
]
}
if len(aliases) > 0:
query["$and"][0]["$or"].append({"aliases": {"$all": aliases}})

existing_skymap = await request.app["mongo"][
config["database"]["collections"]["skymaps"]
].find_one(
{
"$or": [
{"dateobs": dateobs},
{"triggerid": triggerid},
{"aliases": {"$all": aliases}},
],
"localization_name": skymap["localization_name"],
}
)
].find_one(query)

existing_contour_levels = []
missing_contour_levels = []
Expand Down

0 comments on commit 8c3f89f

Please sign in to comment.