james-berkheimer / media_conveyor

Provide the owner of any media library with the ability to safely and easily open up that library to outside users to access and download files.
MIT License
0 stars 0 forks source link

Threading for AWS state deletion #11

Open james-berkheimer opened 9 months ago

james-berkheimer commented 9 months ago

Terminating both EC2 instances and Elasticache clusters takes time with the clusters taking a very long time. I should investigate ways to background these tasks so that the user can move onto to other tasks.

james-berkheimer commented 8 months ago

Some example code to illustrate what I want to do:

import os
import multiprocessing
from tqdm import tqdm

def delete_resource(resource):
    # Simulate long deletion process
    os.remove(resource)
    return 1

resources = [self.aws_state_path, key_pair_path]  # Add all resources to delete here

with multiprocessing.Pool() as pool:
    with tqdm(total=len(resources)) as pbar:
        for i, _ in enumerate(pool.imap_unordered(delete_resource, resources)):
            pbar.update()