Skip to content

Commit

Permalink
Make Exposure.write_to_db staticmethod
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 27, 2024
1 parent 6e434a0 commit e560046
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/gort/exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,16 @@ async def _done_monitor(self):
self.error = True

files = await self.verify_files()
asyncio.create_task(self._write_to_db(files))
exposure_table = self.gort.config["services.database.tables.exposures"]
asyncio.create_task(self.write_to_db(files, exposure_table))

# Set the Future.
self.set_result(self)

async def _write_to_db(self, files: list[pathlib.Path] | None = None):
@staticmethod
async def write_to_db(files: list[pathlib.Path], table_name: str):
"""Records the exposures in ``gortdb.exposure``."""

files = files or self.get_files()

headers: list[dict[str, Any]] = []
for file in files:
header = dict(await run_in_executor(fits.getheader, str(file)))
Expand Down Expand Up @@ -491,8 +491,7 @@ async def _write_to_db(self, files: list[pathlib.Path] | None = None):
}
)

table = self.gort.config["services.database.tables.exposures"]
await run_in_executor(insert_to_database, table, column_data)
await run_in_executor(insert_to_database, table_name, column_data)

async def _call_hook(self, hook_name: str, *args, as_task: bool = False, **kwargs):
"""Calls the coroutines associated with a hook."""
Expand Down

0 comments on commit e560046

Please sign in to comment.