Skip to content

Commit

Permalink
Merge pull request #1875 from Sefaria/catch-state-node-keyerror
Browse files Browse the repository at this point in the history
Catch state node keyerror
  • Loading branch information
nsantacruz authored Apr 10, 2024
2 parents 83b7e90 + 62ff8ee commit b81e226
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 37 deletions.
35 changes: 8 additions & 27 deletions scripts/scheduled/reindex_elasticsearch_cronjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,11 @@
up-to-date mongo dump).
"""
# last_sheet_timestamp = datetime.fromtimestamp(os.path.getmtime("/var/data/sefaria_public/dump/sefaria")).isoformat()
try:
last_sheet_timestamp = datetime.now().isoformat()
update_pagesheetrank()
index_all()
r = requests.post("https://www.sefaria.org/admin/index-sheets-by-timestamp", data={"timestamp": last_sheet_timestamp, "apikey": SEFARIA_BOT_API_KEY})
if "error" in r.text:
raise Exception("Error when calling admin/index-sheets-by-timestamp API: " + r.text)
else:
print("SUCCESS!", r.text)
except Exception as e:
tb_str = traceback.format_exc()
print("Caught exception")
post_object = {
"icon_emoji": ":facepalm:",
"username": "Reindex ElasticSearch",
"channel": "#engineering-discuss",
"attachments": [
{
"fallback": tb_str,
"color": "#a30200",
"pretext": "Cronjob Error",
"text": tb_str
}
]
}
requests.post(os.environ['SLACK_URL'], json=post_object)
raise e
last_sheet_timestamp = datetime.now().isoformat()
update_pagesheetrank()
index_all()
r = requests.post("https://www.sefaria.org/admin/index-sheets-by-timestamp", data={"timestamp": last_sheet_timestamp, "apikey": SEFARIA_BOT_API_KEY})
if "error" in r.text:
raise Exception("Error when calling admin/index-sheets-by-timestamp API: " + r.text)
else:
print("SUCCESS!", r.text)
11 changes: 1 addition & 10 deletions sefaria/pagesheetrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,7 @@ def count_sources(sources):

for r in ref_list:
sheetrank_dict[r.normal()] += 1
except InputError:
continue
except TypeError:
continue
except AssertionError:
continue
except AttributeError:
continue
except IndexError:
print(s["ref"])
except (InputError, TypeError, AssertionError, KeyError, AttributeError, IndexError):
continue

if "subsources" in s:
Expand Down

0 comments on commit b81e226

Please sign in to comment.