Interacting with your Async Service
Interacting with the Application
With the deployment now active, you can click on your specific service. Doing so will open up the dashboard dedicated to your service, allowing you to access various details.
Here, you can see the Endpoint of your service at the top right corner. You can click on the Endpoint to open your application.
Now you can click on one of the Images from the two options and see what predictions your model gives:
Congratulations! You have successfully deployed the async service using Truefoundry.
Sending requests
The request body for sending a synchronous or an asynchronous process request is the same.
Send a synchronous process request
Note:
Enter the endpoint of your application below.
curl '<yourendpoint>/process' -H 'Content-Type: application/json' -d '{"request_id": "abc", "body": {"x": 1, "y": 2}}'
Output:
❯ curl '<yourendpoint>/process' -H 'Content-Type: application/json' -d '{"request_id": "abc", "body": {"x": 1, "y": 2}}'
{"request_id":"abc","status":"SUCCESS","body":2,"error":null}
- A FastAPI documentation dashboard will be available on your endpoint
Send an asynchronous process request
send_async_request.py
import json
import uuid
import boto3
def send_request(input_sqs_url: str, output_sqs_url: str):
sqs = boto3.client("sqs")
request_id = str(uuid.uuid4())
sqs.send_message(
QueueUrl=input_sqs_url,
MessageBody=json.dumps({"request_id": request_id, "body": {"x": 1, "y": 2}})
)
while True:
response = sqs.receive_message(
QueueUrl=output_sqs_url, MaxNumberOfMessages=1, WaitTimeSeconds=19
)
if "Messages" not in response:
continue
msg = response["Messages"][0]
response = json.loads(msg["Body"])
if response.get("status") != "SUCCESS":
raise Exception(f"Processing failed: {response.get('error')}")
print(response)
break
if __name__ == "__main__":
send_request(input_sqs_url="YOUR_INPUT_SQS_URL", output_sqs_url="YOUR_OUTPUT_SQS_URL")
Run the above Python script.
python send_async_request.py
Output:
❯ python send_async_request.py
request_id='46a4ebc6-afdb-46a0-8587-ba29abf0f0d4' status='SUCCESS' body=2 error=None
Updated 10 months ago