-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send a heartbeat message to the topic gcn.heartbeat roughly once per second. Users with flaky Internet connections have requested a high frequency test message to check that their connection is working.
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
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,39 @@ | ||
# | ||
# Copyright © 2023 United States Government as represented by the | ||
# Administrator of the National Aeronautics and Space Administration. | ||
# All Rights Reserved. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
import asyncio | ||
import datetime | ||
import json | ||
import logging | ||
|
||
import confluent_kafka | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
TIMEOUT = 1 | ||
TOPIC = "gcn.heartbeat" | ||
|
||
|
||
async def run(producer: confluent_kafka.Producer): | ||
"""Produce a heartbeat message once per second.""" | ||
log.info("Producing heartbeats every %d second(s) on topic %s", TIMEOUT, TOPIC) | ||
while True: | ||
producer.produce( | ||
TOPIC, | ||
json.dumps( | ||
{ | ||
"$schema": "https://gcn.nasa.gov/docs/schema/v4.1.0/gcn/notices/core/Alert.schema.json", | ||
"alert_datetime": datetime.datetime.now(datetime.UTC).isoformat(), | ||
} | ||
), | ||
) | ||
|
||
# Wait for any outstanding messages to be delivered and delivery | ||
# report callbacks to be triggered. | ||
producer.poll(0) | ||
|
||
await asyncio.sleep(TIMEOUT) |