Skip to content

Commit

Permalink
Optionally disable telegram notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
tsudmi committed Mar 7, 2021
1 parent cd96e28 commit ca47ae4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ where `settings.txt` is an environment file with [Settings](#settings).
| NOTIFIERS_TELEGRAM_TOKEN | Telegram chat token where notifications about low balance or errors will be sent. | No | - |
| NOTIFIERS_TELEGRAM_CHAT_ID | Telegram chat ID where notifications about low balance or errors will be sent. | No | - |
| PROCESS_INTERVAL | How long to wait before processing again. | Yes | - |
| SEND_TELEGRAM_NOTIFICATIONS | Defines whether to send telegram notifications about oracle balance and errors. | No | True |

## Example settings

Expand Down
27 changes: 15 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
LOG_LEVEL,
PROCESS_INTERVAL,
BEACON_CHAIN_RPC_ENDPOINT,
SEND_TELEGRAM_NOTIFICATIONS,
)
from src.utils import (
get_web3_client,
Expand Down Expand Up @@ -66,15 +67,16 @@ def main() -> None:
# wait for interrupt
interrupt_handler = InterruptHandler()

# Notify Telegram the oracle is warming up, so that
# oracle maintainers know the service has restarted
telegram.notify(
message=f"Oracle starting with account [{web3_client.eth.defaultAccount}]"
f"(https://etherscan.io/address/{web3_client.eth.defaultAccount})",
parse_mode="markdown",
raise_on_errors=True,
disable_web_page_preview=True,
)
if SEND_TELEGRAM_NOTIFICATIONS:
# Notify Telegram the oracle is warming up, so that
# oracle maintainers know the service has restarted
telegram.notify(
message=f"Oracle starting with account [{web3_client.eth.defaultAccount}]"
f"(https://etherscan.io/address/{web3_client.eth.defaultAccount})",
parse_mode="markdown",
raise_on_errors=True,
disable_web_page_preview=True,
)

# wait that node is synced before trying to do anything
wait_prysm_ready(interrupt_handler, BEACON_CHAIN_RPC_ENDPOINT, PROCESS_INTERVAL)
Expand All @@ -83,9 +85,10 @@ def main() -> None:
w3=web3_client, interrupt_handler=interrupt_handler
)
# check oracle balance
check_default_account_balance(
web3_client, BALANCE_WARNING_THRESHOLD, BALANCE_ERROR_THRESHOLD
)
if SEND_TELEGRAM_NOTIFICATIONS:
check_default_account_balance(
web3_client, BALANCE_WARNING_THRESHOLD, BALANCE_ERROR_THRESHOLD
)

while not interrupt_handler.exit:
# update Reward Token total rewards
Expand Down
8 changes: 5 additions & 3 deletions src/reward_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
ORACLES_CONTRACT_ADDRESS,
BALANCE_WARNING_THRESHOLD,
BALANCE_ERROR_THRESHOLD,
SEND_TELEGRAM_NOTIFICATIONS,
)
from src.utils import (
InterruptHandler,
Expand Down Expand Up @@ -307,6 +308,7 @@ def process(self) -> None:
logger.info(f"Re-scheduling rewards update: next at={self.next_update_at}")

# check oracle balance
check_default_account_balance(
self.w3, BALANCE_WARNING_THRESHOLD, BALANCE_ERROR_THRESHOLD
)
if SEND_TELEGRAM_NOTIFICATIONS:
check_default_account_balance(
self.w3, BALANCE_WARNING_THRESHOLD, BALANCE_ERROR_THRESHOLD
)
5 changes: 5 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
environ["STALE_CHECK_MIDDLEWARE_ALLOWABLE_DELAY"]
)

# defines whether to enable sending telegram notifications
SEND_TELEGRAM_NOTIFICATIONS: bool = environ.get(
"SEND_TELEGRAM_NOTIFICATIONS", "True"
) in ("True", "true")

# whether to retry http or ws requests
INJECT_RETRY_REQUEST_MIDDLEWARE: bool = environ.get(
"INJECT_RETRY_REQUEST_MIDDLEWARE", "False"
Expand Down

0 comments on commit ca47ae4

Please sign in to comment.