Skip to content

Commit

Permalink
Delete file from cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ppigazzini committed Jan 8, 2025
1 parent 0d50d9b commit 0a34541
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions worker/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ def cache_write(cache, name, data):
return


def cache_remove(cache, name):
"""Remove a file from the global cache on disk"""
if cache == "":
return

try:
(Path(cache) / name).unlink()
except Exception as e:
return


# See https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module
# for background.
# It may be useful to introduce more refined http exception handling in the future.
Expand Down Expand Up @@ -333,7 +344,8 @@ def fetch_validated_net(remote, testing_dir, net, global_cache):
cache_write(global_cache, net, content)
else:
if not is_valid_net(content, net):
print(f"{net} from global cache is invalid")
print(f"{net} from global cache is invalid, removing")
cache_remove(global_cache, net)
return False
print(f"Using {net} from global cache")

Expand All @@ -354,28 +366,24 @@ def validate_net(testing_dir, net):
def establish_validated_net(remote, testing_dir, net, global_cache):
if (testing_dir / net).exists() and validate_net(testing_dir, net):
return

attempts = 5
attempt = 0

attempt, attempts = 0, 5
while True:
attempt += 1
try:
if fetch_validated_net(remote, testing_dir, net, global_cache):
return
else:
raise WorkerException(
"Failed to validate the network: {}".format(net)
)
raise WorkerException(f"Failed to validate the network: {net}")
except FatalException:
raise
except WorkerException:
if attempt > attempts:
raise
waitTime = UPDATE_RETRY_TIME * attempt
print(
"Failed to download {} in attempt {}, trying in {} seconds.".format(
net, attempt, waitTime
)
f"Failed to fetch {net} in attempt {attempt},",
f"trying in {waitTime} seconds"
)
time.sleep(waitTime)

Expand Down
2 changes: 1 addition & 1 deletion worker/sri.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__version": 246, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "NW2mz+hDNprnOcMpw6k8rGUEXE4QvZwkWPma8kYg0uswQ7gQ+OIXBDFK7Fhz/Brt", "games.py": "757WYTqKEY65A7BbUM5+CHIUDVHZn0rJRH0pNsf1gghGG5+nKxkA8zw0riGZCXgu"}
{"__version": 246, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "NW2mz+hDNprnOcMpw6k8rGUEXE4QvZwkWPma8kYg0uswQ7gQ+OIXBDFK7Fhz/Brt", "games.py": "/MyBz+2JVyL/fEq4YLlHGPfr4ayk5avNwxSQVn0kuqeJMgN6HqfJngaFJ4TPSbOu"}

0 comments on commit 0a34541

Please sign in to comment.