-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
149 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# # | ||
# # (C) Copyright 2023 ECMWF. | ||
# # | ||
# # This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# # In applying this licence, ECMWF does not waive the privileges and immunities | ||
# # granted to it by virtue of its status as an intergovernmental organisation nor | ||
# # does it submit to any jurisdiction. | ||
# # | ||
|
||
from typing import Iterable, List, Literal | ||
|
||
import pandas as pd | ||
|
||
import dataclasses | ||
|
||
from ..core.bases import Writer, Message, FileMessage, FinishMessage | ||
from ..core.aviso import send_aviso_notification | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@dataclasses.dataclass | ||
class AVISONotifier(Writer): | ||
def __str__(self): | ||
return f"{self.__class__.__name__}()" | ||
|
||
def init(self, globals): | ||
super().init(globals) | ||
self.metadata = dataclasses.replace(self.metadata, state="aviso_notified") | ||
|
||
def process(self, message: FileMessage | FinishMessage) -> Iterable[Message]: | ||
if isinstance(message, FinishMessage): | ||
return | ||
|
||
request = {"database": "fdbdev", "class": "rd", "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 | request | ||
request = {k: mars_value_formatters.get(k, str)(v) for k, v in request.items()} | ||
|
||
# Send a notification to AVISO that we put this data into the DB | ||
response = send_aviso_notification(request) | ||
logger.debug("Aviso response {response}") | ||
|
||
# TODO: the explicit mars_keys should not be necessary here. | ||
metadata = self.generate_metadata(message, mars_keys=message.metadata.mars_keys) | ||
output_msg = FileMessage(metadata=metadata) | ||
|
||
assert output_msg.metadata.mars_keys is not None | ||
yield self.tag_message(output_msg, message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# # | ||
# # (C) Copyright 2023 ECMWF. | ||
# # | ||
# # This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# # In applying this licence, ECMWF does not waive the privileges and immunities | ||
# # granted to it by virtue of its status as an intergovernmental organisation nor | ||
# # does it submit to any jurisdiction. | ||
# # | ||
|
||
mars_value_formatters = { | ||
"time": lambda t: f"{t:04d}", | ||
} | ||
|
||
|
||
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()} | ||
return request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters