mirror of
https://git.juggalol.com/agatha/gitmon.git
synced 2024-11-22 07:26:41 +00:00
Cleanly exit on SIGINT
This commit is contained in:
parent
1e958b397a
commit
1c6a45a1d2
14
main.py
14
main.py
@ -1,4 +1,5 @@
|
|||||||
"""GitMon"""
|
"""GitMon"""
|
||||||
|
import signal
|
||||||
import time
|
import time
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from gitmon.api import GitHubApi
|
from gitmon.api import GitHubApi
|
||||||
@ -21,11 +22,20 @@ def log_event(event):
|
|||||||
logger.log('CREATE', f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
|
logger.log('CREATE', f'{event_type}:\thttps://github.com/{repo["name"]}, {actor["login"]}')
|
||||||
|
|
||||||
|
|
||||||
|
def sigint_handler(signum, frame):
|
||||||
|
"""Signal handler for Ctrl+C."""
|
||||||
|
raise KeyboardInterrupt
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point."""
|
"""Main entry point."""
|
||||||
|
# Setup logger and signal handling
|
||||||
setup_logger()
|
setup_logger()
|
||||||
|
signal.signal(signal.SIGINT, sigint_handler)
|
||||||
|
|
||||||
api = GitHubApi(token)
|
api = GitHubApi(token)
|
||||||
|
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
events = api.get_events()
|
events = api.get_events()
|
||||||
for event in events:
|
for event in events:
|
||||||
@ -35,7 +45,9 @@ def main():
|
|||||||
):
|
):
|
||||||
log_event(event)
|
log_event(event)
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logger.info('Program terminating')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user