diff --git a/scripts/submit_job.py b/scripts/submit_job.py index ac81d1e..41d7940 100755 --- a/scripts/submit_job.py +++ b/scripts/submit_job.py @@ -5,6 +5,7 @@ import subprocess import tempfile import os import time +import socket # Force temp files into a folder inside your project (fully owned by you) custom_temp_dir = os.path.join(os.getcwd(), "tmp") @@ -17,6 +18,32 @@ MVSHOST = "oldcomputernerd.com" RDRPORT = 3505 MVS_PASSWORD = os.environ.get("MVS_BATCH_PASSWORD") +def wait_for_port(host, port, timeout=30, poll_interval=1): + """Wait for port to become available (not in use)""" + print(f"Waiting for port {port} on {host} to be ready...") + start_time = time.time() + + while time.time() - start_time < timeout: + try: + # Try to connect - if successful, port is available + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.settimeout(2) + result = sock.connect_ex((host, port)) + sock.close() + + if result == 0: + print(f"Port {port} is ready") + return True + else: + print(f"Port {port} not responding (error {result}), waiting...") + time.sleep(poll_interval) + except socket.error as e: + print(f"Socket error: {e}, retrying...") + time.sleep(poll_interval) + + print(f"Timeout waiting for port {port} to be ready after {timeout}s") + return False + def create_jcl_payload(local_file, dataset_name, member_name): @@ -171,9 +198,10 @@ if __name__ == "__main__": if upload_source(local_file, dataset_name, member_name, mvshost) != 0: sys.exit(1) - # Wait between submissions to avoid overwhelming the card reader - print("Waiting 3 seconds before submitting compile job...") - time.sleep(3) + # Wait for card reader port to be ready before submitting compile job + if not wait_for_port(mvshost, RDRPORT, timeout=30): + print(f"Error: Card reader port {RDRPORT} not available") + sys.exit(1) # Step 2: Submit JCL job exit_code = submit_jcl(job, mvshost)