DinoPLayZ commited on
Commit
1408c56
·
verified ·
1 Parent(s): d10ce1c

Logs Filtered

Browse files
Files changed (1) hide show
  1. main.py +10 -11
main.py CHANGED
@@ -11,6 +11,7 @@ from dotenv import load_dotenv
11
  import threading
12
  import asyncio
13
 
 
14
  from fastapi import FastAPI, BackgroundTasks
15
  import uvicorn
16
 
@@ -476,10 +477,7 @@ def test_real_event_alert():
476
  logger.info("✅ Real latest event alert sent successfully!")
477
 
478
  def start_loop():
479
- logger.info("=" * 60)
480
  logger.info("🚀 BIP CLI Notifier Started")
481
- logger.info("=" * 60)
482
- logger.info("Press Ctrl+C to stop the notifier at any time.\n")
483
 
484
  try:
485
  while True:
@@ -519,16 +517,18 @@ def start_loop():
519
  # ==============================================================================
520
  # FASTAPI MICROSERVICE (Task 10)
521
  # ==============================================================================
522
- app = FastAPI(title="BIP Auto Notifier")
523
-
524
  def background_scraper_loop():
525
  """Runs the main notification loop within the FastAPI background."""
526
  start_loop()
527
 
528
- @app.on_event("startup")
529
- async def startup_event():
530
- logger.info("FastAPI starting up. Launching background tracker thread...")
531
  threading.Thread(target=background_scraper_loop, daemon=True).start()
 
 
 
 
532
 
533
  @app.get("/health")
534
  async def health_check():
@@ -593,7 +593,6 @@ async def internal_assistant():
593
  }
594
 
595
  if __name__ == "__main__":
596
- logger.info("Starting BIP CLI Notifier...")
597
  parser = argparse.ArgumentParser(description="BIP Cloud Notifier CLI")
598
  parser.add_argument("--list-all", action="store_true", help="List all recent events and exit")
599
  parser.add_argument("--latest", action="store_true", help="Print details of the latest event and exit")
@@ -616,8 +615,8 @@ if __name__ == "__main__":
616
  elif args.run:
617
  # Launch FastAPI which internally starts the loop
618
  port = int(os.getenv("PORT", 7860))
619
- uvicorn.run(app, host="0.0.0.0", port=port)
620
  else:
621
  # Default behavior: run FastAPI
622
  port = int(os.getenv("PORT", 7860))
623
- uvicorn.run(app, host="0.0.0.0", port=port)
 
11
  import threading
12
  import asyncio
13
 
14
+ from contextlib import asynccontextmanager
15
  from fastapi import FastAPI, BackgroundTasks
16
  import uvicorn
17
 
 
477
  logger.info("✅ Real latest event alert sent successfully!")
478
 
479
  def start_loop():
 
480
  logger.info("🚀 BIP CLI Notifier Started")
 
 
481
 
482
  try:
483
  while True:
 
517
  # ==============================================================================
518
  # FASTAPI MICROSERVICE (Task 10)
519
  # ==============================================================================
 
 
520
  def background_scraper_loop():
521
  """Runs the main notification loop within the FastAPI background."""
522
  start_loop()
523
 
524
+ @asynccontextmanager
525
+ async def lifespan(app: FastAPI):
526
+ # Startup
527
  threading.Thread(target=background_scraper_loop, daemon=True).start()
528
+ yield
529
+ # Shutdown (nothing to do here currently)
530
+
531
+ app = FastAPI(title="BIP Auto Notifier", lifespan=lifespan)
532
 
533
  @app.get("/health")
534
  async def health_check():
 
593
  }
594
 
595
  if __name__ == "__main__":
 
596
  parser = argparse.ArgumentParser(description="BIP Cloud Notifier CLI")
597
  parser.add_argument("--list-all", action="store_true", help="List all recent events and exit")
598
  parser.add_argument("--latest", action="store_true", help="Print details of the latest event and exit")
 
615
  elif args.run:
616
  # Launch FastAPI which internally starts the loop
617
  port = int(os.getenv("PORT", 7860))
618
+ uvicorn.run(app, host="0.0.0.0", port=port, log_level="warning")
619
  else:
620
  # Default behavior: run FastAPI
621
  port = int(os.getenv("PORT", 7860))
622
+ uvicorn.run(app, host="0.0.0.0", port=port, log_level="warning")