Skip to content

Commit

Permalink
add aviso notification
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHodson committed Dec 8, 2023
1 parent 12294c4 commit 03d293d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/ionbeam/core/aviso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import requests
from typing import Any
from datetime import datetime


def send_aviso_notification(request: dict[str, Any]):
notification = {
"type": "aviso",
"data": {"event": "iot-data", "request": request},
"datacontenttype": "application/json",
"id": "0c02fdc5-148c-43b5-b2fa-cb1f590369ff",
"source": "/host/user",
"specversion": "1.0",
"time": datetime.utcnow().isoformat(timespec="milliseconds") + "Z",
}

response = requests.post("https://iot-notifications.ecmwf.int/api/v1/notification", json=notification)
# response.raise_for_status()
return response
3 changes: 2 additions & 1 deletion src/ionbeam/writers/mars_client_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import dataclasses

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

import logging

Expand Down Expand Up @@ -97,7 +98,7 @@ def process(self, message: FileMessage | FinishMessage) -> Iterable[Message]:
logger.debug(mars_request)
run_temp_mars_request(file=fp.name)

# send an aviso notification here
response = send_aviso_notification(request)

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

0 comments on commit 03d293d

Please sign in to comment.