Francisco Schulz 05d5582479 convert into python package
- remove build specs
- move pytest.ini into pyproject.toml
- update readme
- add pre-commit config
- run formatters
- add Makefile
2022-11-03 16:10:12 +01:00

37 lines
1.1 KiB
Python

import logging
import sys
from pathlib import Path
from pyinfra.queue.queue_manager import token_file_name
def check_token_file():
"""
Checks if the token file of the QueueManager exists and is not empty, i.e. the queue manager has been started.
NOTE: This function suppresses all Exception's.
Returns True if the queue manager has been started, False otherwise
"""
try:
token_file_path = Path(token_file_name())
if token_file_path.exists():
with token_file_path.open(mode="r", encoding="utf8") as token_file:
contents = token_file.read().strip()
return contents != ""
# We're intentionally do not handle exception here, since we're only using this in a short script.
# Take care to expand this if the intended use changes
except Exception:
logging.getLogger(__file__).info("Caught exception when reading from token file", exc_info=True)
return False
if __name__ == "__main__":
if check_token_file():
sys.exit(0)
else:
sys.exit(1)