Skip to content

Commit 926093c

Browse files
committed
feat: concurrency!
1 parent 958dae0 commit 926093c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import shutil
77
from logfmter import Logfmter
8+
import concurrent.futures
89

910
logger = logging.getLogger("appstream-generator")
1011

@@ -34,6 +35,9 @@
3435
# Limits N number of old entries
3536
old_limit = int(os.environ.get("OLD_LIMIT", 5))
3637

38+
# Max concurrent tasks
39+
max_workers = int(os.environ.get("MAX_WORKERS", 5))
40+
3741

3842
def scan_base_dir(base_dir: str):
3943
for entry in os.scandir(base_dir):
@@ -273,13 +277,20 @@ def process_repo(path: str):
273277
except Exception as e:
274278
logger.error(f"Error processing repo {repo_name}: {e}")
275279
return
280+
finally:
281+
return True
276282

277283

278284
def main():
279285
# setup_logging()
280286
# logger.info("test")
287+
thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=max_workers)
288+
futures = []
281289
for dir in scan_base_dir(base_dir):
282-
process_repo(dir)
290+
futures.append(thread_pool.submit(process_repo, dir))
291+
_ = concurrent.futures.wait(futures)
292+
thread_pool.shutdown(wait=True)
293+
thread_pool = None
283294

284295

285296
if __name__ == "__main__":

0 commit comments

Comments
 (0)