Skip to content

Commit

Permalink
supervisord listener for updating clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Maslanka committed Dec 13, 2023
1 parent 549495b commit 9e3f5a8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
42 changes: 37 additions & 5 deletions bin/update_clients.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#! /usr/bin/env python3

import toml, json, subprocess
import toml, json, subprocess, sys
from datetime import datetime, time

HERMES = "hermes"
HERMES = "/usr/local/bin/hermes"
HERMES_CONFIG = "/hermes/config.toml"


Expand Down Expand Up @@ -75,9 +76,40 @@ def update_clients():
result = output["result"]

if output["status"] == "success":
print(f"Success: {client_id} ({chain_id})")
write_stderr(f"Success: {client_id} ({chain_id})\n")
else:
print(f"Failed: {result}")
write_stderr(f"Failed: {result}\n")


update_clients()
def is_update_time():
current_time = datetime.utcnow().time()

update_start_time = time(0, 0)
update_end_time = time(1, 0)

return update_start_time <= current_time < update_end_time


def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()


def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()


def main():
while True:
write_stdout("READY\n")
sys.stdin.readline()

if is_update_time():
update_clients()

write_stdout("RESULT 2\nOK")


if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions etc/supervisor.d/update_clients.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[eventlistener:update_clients]
command=/usr/local/bin/update_clients.py
user=hermes
environment=HOME="/hermes"
autostart=true
events=TICK_3600
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

0 comments on commit 9e3f5a8

Please sign in to comment.