Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel committed May 7, 2024
1 parent fc15359 commit 2e749bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
12 changes: 11 additions & 1 deletion pyth_observer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from prometheus_client import start_http_server

from pyth_observer import Observer, Publisher
from pyth_observer.models import ContactInfo


@click.command()
Expand Down Expand Up @@ -40,7 +41,16 @@ def run(config, publishers, coingecko_mapping, prometheus_port):
# Load publishers YAML file and convert to dictionary of Publisher instances
publishers_raw = yaml.safe_load(open(publishers, "r"))
publishers_ = {
publisher["key"]: Publisher(**publisher) for publisher in publishers_raw
publisher["key"]: Publisher(
key=publisher["key"],
name=publisher["name"],
contact_info=(
ContactInfo(**publisher["contact_info"])
if "contact_info" in publisher
else None
),
)
for publisher in publishers_raw
}
coingecko_mapping_ = yaml.safe_load(open(coingecko_mapping, "r"))
observer = Observer(
Expand Down
5 changes: 2 additions & 3 deletions pyth_observer/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ async def send(self):


class TelegramEvent(Event):
def __init__(self, check: Check, context: Context):
def __init__(self, check: PublisherCheck, context: Context):
self.check = check
self.context = context

async def send(self):
text = self.check.error_message()
# Extract the publisher key from the message text
publisher_key = text[text.find("(") + 1 : text.find(")")]
publisher_key = self.check.state().public_key.key
publisher = self.context["publishers"].get(publisher_key, None)
# Ensure publisher is not None and has contact_info before accessing telegram_chat_id
chat_id = (
Expand Down
8 changes: 4 additions & 4 deletions sample.publishers.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
- name: publisher1
key: "66wJmrBqyykL7m4Erj4Ud29qhsm32DHSTo23zooupJrJ"
key: "FR19oB2ePko2haah8yP4fhTycxitxkVQTxk3tssxX1Ce"
contact_info:
# Optional fields for contact information
telegram_chat_id:
telegram_chat_id: -4224704640
email:
slack_channel_id:

- name: publisher2
key: "3BkoB5MBSrrnDY7qe694UAuPpeMg7zJnodwbCnayNYzC"
key: "DgAK7fPveidN72LCwCF4QjFcYHchBZbtZnjEAtgU1bMX"
contact_info:
# Optional fields for contact information
telegram_chat_id:
telegram_chat_id: -4224704640
email:
slack_channel_id:

0 comments on commit 2e749bc

Please sign in to comment.