Skip to content

Commit

Permalink
Fix some coding style issues in TAP code
Browse files Browse the repository at this point in the history
Use snake_case instead of camelCase. Log whether the query was run
sync or async. Delete a disabled SQL query for DP0.2 data; we have
revision control, we don't need to rename files rather than
deleting them.
  • Loading branch information
rra committed Mar 17, 2023
1 parent ff06058 commit 4c23f0f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 19 deletions.
16 changes: 7 additions & 9 deletions src/mobu/business/tapqueryrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def _generate_parameters(self) -> dict[str, int | float | str]:
"username": self.user.username,
"query_id": "mobu-" + shortuuid.uuid(),
}
objectIds = self._params.get("objectIds")
if objectIds:
result["object"] = str(random.choice(objectIds))
object_ids = self._params.get("object_ids")
if object_ids:
result["object"] = str(random.choice(object_ids))
result["objects"] = ", ".join(
str(o) for o in random.choices(objectIds, k=12)
str(o) for o in random.choices(object_ids, k=12)
)
return result

Expand Down Expand Up @@ -154,19 +154,17 @@ async def execute(self) -> None:
self.logger.info(f"Query finished after {elapsed} seconds")

async def run_async_query(self, query: str) -> None:
self.logger.info("Running: %s", query)
self.logger.info("Running (async): %s", query)
job = self._client.submit_job(query)

try:
job.run()

while job.phase not in ["COMPLETED", "ERROR"]:
while job.phase not in ("COMPLETED", "ERROR"):
await asyncio.sleep(30)
finally:
job.delete()

async def run_sync_query(self, query: str) -> None:
self.logger.info("Running: %s", query)
self.logger.info("Running (sync): %s", query)
loop = asyncio.get_event_loop()
await loop.run_in_executor(self._pool, self._client.search, query)

Expand Down
2 changes: 1 addition & 1 deletion src/mobu/templates/tapqueryrunner/dp0.1/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ min_dec: -42.0
max_dec: -30.0

# 500 randomly selected objects across the entire spatial extent of DP0.1.
objectIds:
object_ids:
- 15995858369670638
- 15147293091046069
- 15138492703093404
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ max_dec: -28.0

# Source list of 500 randomly selected objects across the entire spatial
# extent of DP0.2.
objectIds:
object_ids:
- 2093848371285467432
- 1912481729260552963
- 1821389389922580341
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ max_dec: -28.0

# Source list of 500 randomly selected objects across the entire spatial
# extent of DP0.2.
objectIds:
object_ids:
- 2093848371285467432
- 1912481729260552963
- 1821389389922580341
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion src/mobu/templates/tapqueryrunner/dp0.2/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ radius_near_range: 0.028

# Source list of 500 randomly selected objects across the entire spatial
# extent of DP0.2.
objectIds:
object_ids:
- 2093848371285467432
- 1912481729260552963
- 1821389389922580341
Expand Down
6 changes: 3 additions & 3 deletions tests/business/tapqueryrunner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async def test_alert(

@pytest.mark.asyncio
async def test_random_object() -> None:
for query_set in ["dp0.1", "dp0.2"]:
for query_set in ("dp0.1", "dp0.2"):
params_path = (
Path(mobu.__file__).parent
/ "templates"
Expand All @@ -164,12 +164,12 @@ async def test_random_object() -> None:
/ "params.yaml"
)
with params_path.open("r") as f:
objects = [str(o) for o in yaml.safe_load(f)["objectIds"]]
objects = [str(o) for o in yaml.safe_load(f)["object_ids"]]

logger = structlog.get_logger(__file__)
user = AuthenticatedUser(
username="user", scopes=["read:tap"], token="blah blah"
)
logger = structlog.get_logger(__file__)
with patch.object(pyvo.dal, "TAPService"):
runner = TAPQueryRunner(
logger, BusinessConfig(tap_query_set=query_set), user
Expand Down

0 comments on commit 4c23f0f

Please sign in to comment.