Use file based locking when running script locally

Fixes #18
This commit is contained in:
nanos 2023-03-20 21:14:08 +00:00
parent 5be011b8d9
commit 62989f4041

View file

@ -683,6 +683,17 @@ class OrderedSet:
if __name__ == "__main__":
LOCK_FILE = 'artifacts/lock.lock'
if( os.path.exists(LOCK_FILE)):
log(f"Lock file exists at {LOCK_FILE}")
sys.exit(1)
with open(LOCK_FILE, "w", encoding="utf-8") as f:
f.write(f"{datetime.now()}")
try:
SEEN_URLS_FILE = "artifacts/seen_urls"
REPLIED_TOOT_SERVER_IDS_FILE = "artifacts/replied_toot_server_ids"
KNOWN_FOLLOWINGS_FILE = "artifacts/known_followings"
@ -727,3 +738,9 @@ if __name__ == "__main__":
with open(REPLIED_TOOT_SERVER_IDS_FILE, "w", encoding="utf-8") as f:
json.dump(dict(list(REPLIED_TOOT_SERVER_IDS.items())[-10000:]), f)
os.remove(LOCK_FILE)
except Exception as ex:
os.remove(LOCK_FILE)
raise