Skip to content

Commit

Permalink
Changes for fdbdev
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHodson committed Jan 18, 2024
1 parent 931cdb3 commit 7e93eda
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/ionbeam/encoders/odb.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def encode(self, msg: TabularMessage | FinishMessage) -> Iterable[FileMessage]:
kwargs = dict(
observation_variable=msg.metadata.observation_variable,
source=msg.metadata.source,
date=output_df["date"][0],
time=output_df["time"][0],
date=output_df["date@hdr"][0],
time=output_df["time@hdr"][0],
)
f = f.format(**kwargs)

Expand Down
8 changes: 3 additions & 5 deletions src/ionbeam/writers/construct_mars_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
}


def construct_mars_request(message, override=dict(database="fdbdev")):
source = {"source": message.metadata.filepath}
odb_keys = {k.key: k.value for k in message.metadata.mars_keys if not k.reason == "Skipped"}
request = odb_keys | source | override # rightmost dict takes precedence here
request = {k: mars_value_formatters.get(k, str)(v) for k, v in request.items()}
def construct_mars_request(message):
request = {"database": "fdbdev", "class": "rd", "source": str(message.metadata.filepath)}
request |= message.metadata.mars_request.as_strings()
return request
44 changes: 25 additions & 19 deletions src/ionbeam/writers/mars_client_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from ..core.bases import Writer, Message, FileMessage, FinishMessage
from ..core.aviso import send_aviso_notification
from .construct_mars_request import construct_mars_request


import logging
Expand All @@ -34,14 +33,14 @@ def write_temp_mars_request(
request,
file,
verb="archive",
# quote_keys = {"source", "target", "filter"}
quote_keys = {"source", "target", "filter"}
):
keys = []
for key, value in request.items():
# if key in quote_keys:
keys.append(f'{key}="{value}"')
# else:
# keys.append(f'{key}={value}')
if key in quote_keys:
keys.append(f'{key}="{value}"')
else:
keys.append(f'{key}={value}')

keys = ",\n ".join(keys)
rendered = f"""{verb},
Expand All @@ -55,12 +54,12 @@ def write_temp_mars_request(

def run_temp_mars_request(file):
try:
output = sb.check_output(["mars", "/home/math/temp_request.mars"], stderr=sb.STDOUT)
output = sb.check_output(["mars", file], stderr=sb.STDOUT)
except sb.CalledProcessError as exc:
print("Status : FAIL", exc.returncode, exc.output.decode())
raise exc
# else:
# print("Output: \n{}\n".format(output))
else:
logger.debug("MARS Archive Output: \n{}\n".format(output))


@dataclasses.dataclass
Expand All @@ -76,23 +75,30 @@ def process(self, message: FileMessage | FinishMessage) -> Iterable[Message]:
if isinstance(message, FinishMessage):
return

assert message.metadata.mars_keys is not None
assert message.metadata.mars_request is not None
assert message.metadata.filepath is not None

mars_request = construct_mars_request(message)

with tempfile.NamedTemporaryFile() as fp:
mars_request_string = write_temp_mars_request(mars_request, file=fp.name)
logger.debug(mars_request_string)
run_temp_mars_request(file=fp.name)

request = {"database": "fdbdev", "class": "rd", "source": str(message.metadata.filepath)}
mars_request = request | message.metadata.mars_request.as_strings()

logger.info(f"mars_request: {mars_request}")

# with tempfile.NamedTemporaryFile() as fp:
# mars_request_string = write_temp_mars_request(mars_request, file=fp.name)
# logger.debug(f"mars_request_string: {mars_request_string}")
# run_temp_mars_request(file=fp.name)

mars_request_string = write_temp_mars_request(mars_request, file="/home/math/tmp_mars_request")
logger.debug(f"mars_request_string: {mars_request_string}")
run_temp_mars_request(file="/home/math/tmp_mars_request")

# Send a notification to AVISO that we put this data into the DB
response = send_aviso_notification(mars_request)
# logger.debug("Aviso respose {response}")

# TODO: the explicit mars_keys should not be necessary here.
metadata = self.generate_metadata(message, mars_keys=message.metadata.mars_keys)
metadata = self.generate_metadata(message, mars_request=message.metadata.mars_request)
output_msg = FileMessage(metadata=metadata)

assert output_msg.metadata.mars_keys is not None
assert output_msg.metadata.mars_request is not None
yield self.tag_message(output_msg, message)

0 comments on commit 7e93eda

Please sign in to comment.