added PSO calling
This commit is contained in:
+25
@@ -46,12 +46,37 @@ def make_requests() -> None:
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error while requesting {full_url}: {e}")
|
||||
|
||||
def make_pso_request() -> None:
|
||||
base_url, token = load_env_vars()
|
||||
|
||||
if not base_url or not token:
|
||||
return
|
||||
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
full_url = f"{base_url}/api/pso/"
|
||||
|
||||
with requests.Session() as session:
|
||||
try:
|
||||
response = session.get(full_url, headers=headers, timeout=10)
|
||||
response.raise_for_status()
|
||||
|
||||
if response.status_code == 200:
|
||||
logging.info("PSO Updated!")
|
||||
logging.info(f"Success: {full_url} - Response: {response.json()}")
|
||||
except requests.exceptions.Timeout:
|
||||
logging.error(f"Request to {full_url} timed out")
|
||||
except requests.exceptions.HTTPError as e:
|
||||
logging.error(f"HTTP error occurred: {e}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Error while requesting {full_url}: {e}")
|
||||
|
||||
def run_threaded(job_func):
|
||||
job_thread = threading.Thread(target=job_func)
|
||||
job_thread.start()
|
||||
|
||||
def schedule_daily_request():
|
||||
schedule.every().day.at("00:00:00").do(run_threaded, make_requests)
|
||||
schedule.every().day.at("12:00:00").do(run_threaded, make_pso_request)
|
||||
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
|
||||
Reference in New Issue
Block a user