Skip to content

Commit fdb0667

Browse files
maaikelimperCopilot
andcommitted
add GTS headers support
Co-authored-by: Copilot <copilot@github.com>
1 parent 8a04994 commit fdb0667

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

wis2box_api/plugins/process/synop2bufr.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,25 @@ def execute(self, data):
132132
"""
133133

134134
LOGGER.info('Executing process {}'.format(self.name))
135-
135+
gts_headers = None
136136
try:
137137
notify = data['notify']
138138
metadata_id = data.get('metadata_id', None)
139139
channel = data.get('channel', None)
140+
gts_ttaaii = data.get('gts_ttaaii', None)
141+
gts_cccc = data.get('gts_cccc', None)
140142
if metadata_id is None and notify:
141143
raise Exception('metadata_id must be provided if notify is True') # noqa
142144
except Exception as err:
143145
return handle_error({err})
144146

147+
gts_headers = None
148+
if gts_ttaaii is not None and gts_cccc is not None:
149+
gts_headers = {
150+
'ttaaii': gts_ttaaii,
151+
'cccc': gts_cccc
152+
}
153+
145154
# get the channel from the metadata
146155
if channel is None:
147156
try:
@@ -211,7 +220,7 @@ def execute(self, data):
211220

212221
LOGGER.debug(f'synop2bufr-transform returned {len(output_items)} items') # noqa
213222

214-
return data_handler.process_items(output_items)
223+
return data_handler.process_items(output_items, gts_headers=gts_headers) # noqa
215224

216225
def __repr__(self):
217226
return '<submit> {}'.format(self.name)

wis2box_api/wis2box/handle.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ def __init__(self, channel, notify, metadata_id=None):
7979
self._channel = channel.replace('origin/a/wis2/', '')
8080
self.metadata_id = metadata_id
8181

82-
def process_items(self, output_items: []):
82+
def process_items(self, output_items: [], gts_headers: dict = None):
8383
"""Process output_items, store and publish them
8484
8585
:param output_items: list of output-items from the transform
86+
:param gts_headers: optional dict of GTS headers for notification
8687
8788
:returns: 'application/json'
8889
"""
@@ -163,7 +164,7 @@ def process_items(self, output_items: []):
163164
})
164165
if self._notify:
165166
# send the last entry in the data list as a notification
166-
result = self.send_data_publish_request(data[-1])
167+
result = self.send_data_publish_request(data[-1], gts_headers=gts_headers) # noqa
167168
if result != 'success':
168169
errors.append(f'{result}')
169170
else:
@@ -188,7 +189,7 @@ def process_items(self, output_items: []):
188189

189190
return mimetype, outputs
190191

191-
def send_data_publish_request(self, data_item: dict):
192+
def send_data_publish_request(self, data_item: dict, gts_headers: dict = None): # noqa
192193
"""Send DataPublishRequest
193194
194195
:param data: data_item
@@ -205,6 +206,8 @@ def send_data_publish_request(self, data_item: dict):
205206
'filename': data_item['filename'],
206207
'_meta': data_item['_meta']
207208
}
209+
if gts_headers is not None:
210+
msg['gts'] = gts_headers
208211
# publish notification on internal broker
209212
private_auth = {
210213
'username': BROKER_USERNAME,

0 commit comments

Comments
 (0)