Last active
August 24, 2023 13:51
-
-
Save mwestwood/b3e8c061cffe72370b21f7291f40e71f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
# Function to start the job | |
def start_job(start_endpoint): | |
response = requests.post(start_endpoint) | |
if response.status_code == 200: | |
print("Job started successfully.") | |
else: | |
print("Failed to start the job.") | |
exit() | |
# Function to check job status | |
def check_job_status(status_endpoint): | |
response = requests.get(status_endpoint) | |
data = response.json() | |
job_status = data.get("jobStatus") | |
return job_status | |
# Main function | |
def main(): | |
start_endpoint = "start_job_endpoint_here" | |
status_endpoint = "check_status_endpoint_here" | |
# Start the job | |
start_job(start_endpoint) | |
while True: | |
job_status = check_job_status(status_endpoint) | |
if job_status == "completed": | |
print("Job completed.") | |
break | |
elif job_status == "running": | |
print("Job is still in progress. Waiting for 30 seconds...") | |
time.sleep(30) # Wait for 30 seconds and then check again | |
else: | |
print("Unknown job status.") | |
break | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment