Skip to content

Commit efa8a1c

Browse files
committed
Fix: Better way of dealing with collisions on AWS batch
1 parent 9a6d110 commit efa8a1c

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ def main(
2828
config = yaml.safe_load(preprocessed_yaml)
2929

3030
def get_output_path() -> Path:
31-
timestamp = time.strftime("%y%m%d%H%M%S")
31+
if is_running_in_aws_batch():
32+
# Offset timestamp by random seconds to avoid collisions
33+
# Hopefully that means we can just remove the uuid part later on
34+
offset = random.randint(0, 600)
35+
timestamp = time.strftime("%y%m%d%H%M%S", time.localtime(time.time() + offset))
36+
else:
37+
timestamp = time.strftime("%y%m%d%H%M%S")
3238
rounds = config["tournament"]["rounds"]
3339
sims = config["game"]["sims_per_round"]
3440

@@ -40,8 +46,7 @@ def get_output_path() -> Path:
4046
f"PvpTournament.{config['game']['name']}.r{rounds}.s{sims}.p{p_num}.{p_list}{suffix_part}.{timestamp}"
4147
)
4248
if is_running_in_aws_batch():
43-
# Wait a random time to hopefully avoid collisions with the timestamp even without the uuid
44-
time.sleep(random.random() * 20)
49+
# Also add a UUID just to be safe
4550
_uuid = str(uuid.uuid4())
4651
folder_name += f".{_uuid}-uuid"
4752
if output_dir is None:

0 commit comments

Comments
 (0)