Update README.md
This commit is contained in:
66
test_nomad_connection.py
Normal file
66
test_nomad_connection.py
Normal file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Test script to verify Nomad connection and check for specific jobs.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
from pprint import pprint
|
||||
from app.services.nomad_client import NomadService
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
def main():
|
||||
print("Testing Nomad connection...")
|
||||
|
||||
# Check if NOMAD_ADDR is configured
|
||||
nomad_addr = os.getenv("NOMAD_ADDR")
|
||||
if not nomad_addr:
|
||||
print("Error: NOMAD_ADDR is not configured in .env file.")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"Connecting to Nomad at: {nomad_addr}")
|
||||
|
||||
try:
|
||||
# Initialize the Nomad service
|
||||
nomad_service = NomadService()
|
||||
|
||||
# List all jobs
|
||||
print("\nListing all jobs...")
|
||||
jobs = nomad_service.list_jobs()
|
||||
print(f"Found {len(jobs)} jobs:")
|
||||
|
||||
# Print each job's ID and status
|
||||
for job in jobs:
|
||||
print(f" - {job.get('ID')}: {job.get('Status')}")
|
||||
|
||||
# Look for specific job
|
||||
job_id = "ms-qc-db-dev"
|
||||
print(f"\nLooking for job '{job_id}'...")
|
||||
|
||||
job_found = False
|
||||
for job in jobs:
|
||||
if job.get('ID') == job_id:
|
||||
job_found = True
|
||||
print(f"Found job '{job_id}'!")
|
||||
print(f" Status: {job.get('Status')}")
|
||||
print(f" Type: {job.get('Type')}")
|
||||
print(f" Priority: {job.get('Priority')}")
|
||||
break
|
||||
|
||||
if not job_found:
|
||||
print(f"Job '{job_id}' not found in the list of jobs.")
|
||||
print("Available jobs:")
|
||||
for job in jobs:
|
||||
print(f" - {job.get('ID')}")
|
||||
|
||||
print("\nNomad connection test completed successfully.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error connecting to Nomad: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user