Skip to content

Commit 60ee8fd

Browse files
committed
feat: Added support for the bot to self-restart on crash
1 parent af8a149 commit 60ee8fd

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

wbmbot_v2/helpers/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33

44
# Bot version (MAJOR.MINOR.PATCH)
5-
bot_version = "1.0.2"
5+
bot_version = "1.0.3"
66

77
# Today
88
today = dt.date.today()

wbmbot_v2/main.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ def parse_args():
5353
return parser.parse_args()
5454

5555

56-
# * Script Starts Here
57-
if __name__ == "__main__":
56+
def main():
57+
"""
58+
Initialize & starts the bot
59+
If the bot crashes, it will attempt to restart itself
60+
"""
61+
5862
args = parse_args()
5963

6064
color_me = wbm_logger.ColoredLogger(__appname__)
@@ -99,15 +103,26 @@ def parse_args():
99103
page_changed = False
100104
LOG.info(color_me.cyan(f"Connecting to '{start_url}' 🔗"))
101105

102-
webDriverOperations.process_flats(
103-
web_driver,
104-
user_profile,
105-
start_url,
106-
current_page,
107-
previous_page,
108-
page_changed,
109-
args.interval,
110-
args.test,
111-
)
106+
try:
107+
while True:
108+
webDriverOperations.process_flats(
109+
web_driver,
110+
user_profile,
111+
start_url,
112+
current_page,
113+
previous_page,
114+
page_changed,
115+
args.interval,
116+
args.test,
117+
)
118+
except Exception as e:
119+
LOG.error(color_me.red(f"Bot has crashed... Attempting to restart it now! ❤️‍🩹"))
120+
# Wait for a few seconds before restarting
121+
time.sleep(5)
122+
# Restart the script
123+
main()
124+
112125

113-
# driver.quit()
126+
# * Script Starts Here
127+
if __name__ == "__main__":
128+
main()

0 commit comments

Comments
 (0)