Skip to content

Commit

Permalink
[Deployment] Update EC2 worker submission deletion (#4187)
Browse files Browse the repository at this point in the history
  • Loading branch information
gchhablani authored Oct 5, 2023
1 parent 42f780e commit a0edb0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions scripts/deployment/delete_old_submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
# Define the directory path
tmp_directory = '/tmp'

# Calculate the cutoff time (60 seconds ago)
cutoff_time = time.time() - 60 # 60 seconds
# Calculate the cutoff time (5 minutes ago)
cutoff_time = time.time() - 5 * 60 # 5 minutes ago

# List all directories in /tmp starting with 'tmp'
tmp_folders = [d for d in os.listdir(tmp_directory) if os.path.isdir(os.path.join(tmp_directory, d)) and d.startswith('tmp')]

for folder in tmp_folders:
folder_path = os.path.join(tmp_directory, folder)

# Check if the folder was created more than 60 seconds ago
# Check if the folder was created more than 5 minutes ago
folder_creation_time = os.path.getctime(folder_path)
if folder_creation_time < cutoff_time:
shutil.rmtree(folder_path)
print(f"Deleted folder: {folder_path}")
else:
print(f"Skipped folder: {folder_path} (created less than 60 seconds ago)")
print(f"Skipped folder: {folder_path} (created less than 5 minutes ago)")
2 changes: 1 addition & 1 deletion scripts/deployment/deploy_ec2_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ docker cp "scripts/deployment/delete_old_submissions.py" "worker_${QUEUE}:/code/
# Step 11: Setting up crontab
echo "Step 11/11: Setting up crontab"
echo "@reboot docker restart worker_${QUEUE}" >> workercron
echo "@reboot docker exec -it worker_${QUEUE} python delete_old_submissions.py" >> workercron
echo "@reboot docker exec -it worker_${QUEUE} python delete_old_submissions.py > delete_old_submissions.txt" >> workercron
crontab workercron
rm workercron

0 comments on commit a0edb0a

Please sign in to comment.