Query Task Status
The JobStatusChecker is designed to monitor the status of asynchronous jobs through a WebSocket connection.
Workflow
Initialization: Establish a WebSocket connection to the server using the
base_url
andsubscription_key
.Request Handling:
On a successful connection, initiate status queries with the specified job with its
uuid
.
Status Monitoring:
Periodically send status queries to the server, we recommend submitting queries at 2-second intervals.
Listen for responses from the server and update the job status accordingly.
If the job is completed successfully, perform necessary cleanup actions such as closing the connection.
API Endpoint
Socket
/api/scheduler_socket
Queries
subscription
subscripton_key
Sending a Query
To query the status of a job, send a message to the scheduler socket endpoint with the job's UUID:
// Establish connection with the scheduler socket
const socket = io('/api/scheduler_socket?subscription={subscripton_key}');
// Send a query for the job status
socket.emit('query', '{job_uuid}');
Receiving a Response
The server responds with the status of the job, including details such as the job's UUID, status, and any relevant metrics.
socket.on('message', (data) => {
console.log('Received response:', data);
/*
Output will be:
{
"taskUuid": "{job_uuid}",
"jobStatus": "Succeeded", // Succeeded, Running, Failed
"jobMetricPayload": {
"status": "Done",
"error": "None",
"message": "Process Done",
"percentage": 100
}
}
*/
});
While the specific implementation can vary, the core functionality typically involves:
A WebSocket client that handles the lifecycle of the connection and communication.
Event handlers that react to changes in the connection status and incoming messages.
A mechanism to periodically send requests to the server to check the status of the job.
Examples
import socketio
import time
class JobStatusChecker:
def __init__(self, base_url, subscription_key, uuid):
self.base_url = base_url
self.subscription_key = subscription_key
self.uuid = uuid
self.sio = socketio.Client(logger=True, engineio_logger=True)
@self.sio.event
def connect():
print("Connected to the server.")
self.send_query()
threading.Thread(target=self.send_periodic_queries).start()
@self.sio.event
def disconnect():
print("Disconnected from server.")
@self.sio.on('message', namespace='*')
def message(*args, **kwargs):
if len(args) > 2:
data = args[2]
if data.get('jobStatus') == 'Succeeded':
print("Job Succeeded! Please find the SDF image in history")
self.sio.disconnect()
else:
print("Received event with insufficient arguments.")
def send_query(self):
self.sio.emit('query', self.uuid, namespace='/api/scheduler_socket')
def send_periodic_queries(self):
while True:
time.sleep(3)
self.send_query()
def start(self):
self.sio.connect(f"{self.base_url}/scheduler_socket?subscription={self.subscription_key}",
namespaces=['/api/scheduler_socket'], transports='websocket')
self.sio.wait()
# Check progress
progress_checker = JobStatusChecker(BASE_URL, 'subscription_key', 'task_uuid')
progress_checker.start()
Last updated