Skip to content

Commit

Permalink
CELE-119 feat: Add buffer control flags on curl command
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Dec 19, 2024
1 parent 1c97ab9 commit e095d56
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions ingestion/ingestion/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import os
import subprocess
import sys
from argparse import ArgumentParser, Namespace
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -474,6 +475,7 @@ def upload_em_tiles(

pbar.close()


def trigger_populate_db(args):
try:
api_url = args.populate_db_url
Expand All @@ -492,29 +494,28 @@ def trigger_populate_db(args):
)
return

import subprocess

# Add `stdbuf` to ensure curl is unbuffered
command = [
"stdbuf",
"-oL", # Force line buffering
"curl",
"-u", f"{client_id}:{private_key_id}",
f"{api_url}"
"-N", # Disable buffering in curl
"-u",
f"{client_id}:{private_key_id}",
f"{api_url}",
]

with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as proc:
with subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True
) as proc:
try:
for line in proc.stdout:
print(line, end='') # Print each line as received
print(line, end="", flush=True) # Real-time output
except KeyboardInterrupt:
proc.terminate()
print("\nStreaming interrupted by user.", file=sys.stderr)


except FileNotFoundError as e:
print(f"Error: Credentials file not found. {e}", file=sys.stderr)
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON in the credentials file. {e}", file=sys.stderr)
except Exception as e:
print(f"Unexpected error: {e}", file=sys.stderr)
print(f"An error occurred: {e}", file=sys.stderr)


def ingest_cmd(args: Namespace):
Expand Down

0 comments on commit e095d56

Please sign in to comment.