This repository was archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaster_run_algo.py
More file actions
61 lines (50 loc) · 2.25 KB
/
master_run_algo.py
File metadata and controls
61 lines (50 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import subprocess
import sys
import time
import os
import logging
# Configure the logger
logging.basicConfig(filename='logfile.log', level=logging.INFO,
format='%(asctime)s:%(levelname)s:%(message)s')
# Adjust system path to include the directory where the teams_communicator module is located
script_dir = os.path.dirname(os.path.abspath(__file__)) # Gets the directory where the current script is located
sys.path.append(os.path.join(script_dir, '..', 'DSEalgo_v2')) # Appends the path to the module
from teams_communicator import TeamsCommunicator # Now we can import TeamsCommunicator
# List your scripts in the desired order of execution
scripts = [
"alphavantagetickers.py",
"company_overviews.py",
"selected_pairs_history.py"
]
def check_script_exists(script_path):
if not os.path.exists(script_path):
logging.error(f"Script {script_path} does not exist.")
return False
return True
def run_script_with_retries(script, max_retries=2, wait_time=20):
retries = 0
while retries <= max_retries:
logging.info(f"Attempting to run {script}")
script_path = os.path.join(script_dir, script)
if not check_script_exists(script_path):
logging.error(f"Script file missing: {script}")
break
try:
subprocess.check_call([sys.executable, script_path])
logging.info(f"Successfully ran {script}")
break
except subprocess.CalledProcessError as e:
logging.error(f"Error occurred while running {script}, exit code: {e.returncode}")
retries += 1
if retries <= max_retries:
logging.info(f"Retrying {script} after waiting {wait_time} seconds...")
time.sleep(wait_time)
else:
logging.error(f"Script {script} failed after {max_retries} retries. Skipping this script and moving to the next one.")
break
if __name__ == "__main__":
communicator = TeamsCommunicator("ml_database", "run_logs")
for script in scripts:
run_script_with_retries(script)
success_message = f"The {script} ran successfully."
communicator.send_teams_message(success_message)