Skip to content

Commit 65a4e19

Browse files
committed
Parallelize uploading sandboxes to filetracker
1 parent 800afb3 commit 65a4e19

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import os
2-
import os.path
1+
from concurrent.futures import ProcessPoolExecutor
2+
from pathlib import Path
33

44
from django.core.management.base import BaseCommand
55

66
from oioioi.filetracker.client import get_client
77

88

9+
def upload_sandbox(file):
10+
filetracker = get_client()
11+
filetracker.put_file("/sandboxes/" + file.name, str(file))
12+
13+
914
class Command(BaseCommand):
1015
def add_arguments(self, parser):
1116
parser.add_argument(
@@ -19,17 +24,12 @@ def add_arguments(self, parser):
1924

2025
help = "Upload sandboxes to the Filetracker."
2126

22-
def handle(self, *args, **options):
23-
filetracker = get_client()
2427

28+
def handle(self, *args, **options):
2529
print("--- Saving sandboxes to the Filetracker ...", file=self.stdout)
2630

27-
sandboxes_dir = os.fsencode(options["sandboxes_dir"])
28-
for file in os.listdir(sandboxes_dir):
29-
filename = os.fsdecode(file)
30-
if not filename.endswith(".tar.gz"):
31-
continue
32-
33-
filetracker.put_file("/sandboxes/" + filename, os.path.join(options["sandboxes_dir"], filename))
31+
sandboxes_dir = Path(options["sandboxes_dir"])
32+
with ProcessPoolExecutor() as executor:
33+
executor.map(upload_sandbox, sandboxes_dir.glob('*.tar.gz'))
3434

3535
print("--- Done.", file=self.stdout)

0 commit comments

Comments
 (0)