Skip to content

Commit

Permalink
feat: Added support for the bot to self-restart on crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Vel-San committed Feb 23, 2024
1 parent af8a149 commit 60ee8fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion wbmbot_v2/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

# Bot version (MAJOR.MINOR.PATCH)
bot_version = "1.0.2"
bot_version = "1.0.3"

# Today
today = dt.date.today()
Expand Down
41 changes: 28 additions & 13 deletions wbmbot_v2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ def parse_args():
return parser.parse_args()


# * Script Starts Here
if __name__ == "__main__":
def main():
"""
Initialize & starts the bot
If the bot crashes, it will attempt to restart itself
"""

args = parse_args()

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

webDriverOperations.process_flats(
web_driver,
user_profile,
start_url,
current_page,
previous_page,
page_changed,
args.interval,
args.test,
)
try:
while True:
webDriverOperations.process_flats(
web_driver,
user_profile,
start_url,
current_page,
previous_page,
page_changed,
args.interval,
args.test,
)
except Exception as e:
LOG.error(color_me.red(f"Bot has crashed... Attempting to restart it now! ❤️‍🩹"))
# Wait for a few seconds before restarting
time.sleep(5)
# Restart the script
main()


# driver.quit()
# * Script Starts Here
if __name__ == "__main__":
main()

0 comments on commit 60ee8fd

Please sign in to comment.