Skip to content

Commit

Permalink
Separate the main loop from the setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
It's me, CI committed Feb 15, 2024
1 parent e4ae4d4 commit 605d840
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions uptime_service_validation/coordinator/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,7 @@
sys.path.insert(0, project_root)


def main():
process_loop_count = 0
load_dotenv()

logging.basicConfig(
stream=sys.stdout,
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)

connection = psycopg2.connect(
host=os.environ["POSTGRES_HOST"],
port=os.environ["POSTGRES_PORT"],
database=os.environ["POSTGRES_DB"],
user=os.environ["POSTGRES_USER"],
password=os.environ["POSTGRES_PASSWORD"],
)

# Step 1 Get previous record and build relations list
interval = int(os.environ["SURVEY_INTERVAL_MINUTES"])
prev_batch_end, cur_batch_end, bot_log_id = getBatchTimings(
connection, logging, interval
)

def process(connection, prev_batch_end, cur_batch_end, bot_log_id):
while True:
cur_timestamp = datetime.now(timezone.utc)
logging.info(
Expand Down Expand Up @@ -307,6 +284,31 @@ def main():
cur_timestamp,
)

def main():
process_loop_count = 0
load_dotenv()

logging.basicConfig(
stream=sys.stdout,
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)

connection = psycopg2.connect(
host=os.environ["POSTGRES_HOST"],
port=os.environ["POSTGRES_PORT"],
database=os.environ["POSTGRES_DB"],
user=os.environ["POSTGRES_USER"],
password=os.environ["POSTGRES_PASSWORD"],
)

# Step 1 Get previous record and build relations list
interval = int(os.environ["SURVEY_INTERVAL_MINUTES"])
prev_batch_end, cur_batch_end, bot_log_id = getBatchTimings(
connection, logging, interval
)
process(connection, prev_batch_end, cur_batch_end, bot_log_id)


if __name__ == "__main__":
main()

0 comments on commit 605d840

Please sign in to comment.