Skip to content

Commit

Permalink
DONT MERGE - not working concurrent implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoWill committed Sep 14, 2023
1 parent a108210 commit 4c34368
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from concurrent.futures import ThreadPoolExecutor
from itertools import chain
from pathlib import Path

Expand Down Expand Up @@ -221,14 +222,14 @@ def create_single_lookup(self):
)
self.stdout.write(f"Output written to: {destination_path}")

def create_outcode_lookup(self, outcode, cursor):
def create_outcode_lookup(self, outcode):
destination_path = self.dst_dir / "outcodes" / f"{outcode.strip()}.csv"
query_string = (
f"{self.single_lookup_query_string()} WHERE a.postcode LIKE '{outcode}%'"
)

self.stdout.write(f"creating lookup {destination_path.name}...")
with destination_path.open("w") as destination:
self.stdout.write(f"Processing {outcode.strip()}...")
with destination_path.open("w") as destination, connection.cursor() as cursor:
cursor.copy_expert(
f"""
COPY ({query_string})
Expand All @@ -242,9 +243,9 @@ def create_outcode_lookup(self, outcode, cursor):
def create_sharded_lookup(self):
(self.dst_dir / "outcodes").mkdir(exist_ok=True, parents=True)
outcodes = self.get_outcodes()
with connection.cursor() as cursor:
with ThreadPoolExecutor(max_workers=4) as executor:
for outcode in outcodes:
self.create_outcode_lookup(outcode, cursor)
executor.submit(self.create_outcode_lookup, outcode)

def get_outcodes(self):
with connection.cursor() as cursor:
Expand Down

0 comments on commit 4c34368

Please sign in to comment.