From 2fbd0cbf5e6c966b5260d07e8422cc4045ccdf43 Mon Sep 17 00:00:00 2001 From: msglm Date: Mon, 23 Jan 2023 11:35:07 -0600 Subject: spruced up the retry feature for slower connections and better stability --- src/indeedwatcher.nim | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/indeedwatcher.nim b/src/indeedwatcher.nim index 69c0071..7419321 100644 --- a/src/indeedwatcher.nim +++ b/src/indeedwatcher.nim @@ -71,13 +71,17 @@ for feed in feeds: #Getting the listing URLs from the feeds var rssFeedReply: RSS - #TODO implement a retry-on-fail system - try: - echo "now reading " & feed - rssFeedReply = getRSS(feed) - except: - raise - + for attempt in countup(0,3): + try: + echo "now reading " & feed + rssFeedReply = getRSS(feed) + except: + if attempt < 3: + echo "Recieved an error: trying again..." + continue + else: + raise + break for entry in rssFeedReply.items: #Sleep so indeed.com doesn't freak out @@ -90,8 +94,17 @@ for feed in feeds: var URL = entry.link let URLID = entry.link.split('&')[3] if not any(cache, proc (input: string): bool = input.contains(URLID)): - echo "Telling chromium to navigate to " & URL - session.navigate(URL) + for attempt in countup(0,3): + try: + echo "Telling chromium to navigate to " & URL + session.navigate(URL) + except: + if attempt < 3: + echo "Recieved an error: trying again..." + continue + else: + raise + break counter = counter + 1 #HTML Parser -- cgit v1.2.3