API endpoints with sockets
API calls exceeding one minute will result in a timeout. To address this, we have introduced a socket connection mechanism working the following way:
Client Initiation. A client initiates a room designated for the given tenant ID and project ID.
API Request Dispatch. The client proceeds to dispatch the API request to the server. What is important is that this request is promptly concluded without delay.
Server Processing. Upon receiving the request, the server begins processing the request to generate the desired content. As soon as this task is completed, the server communicates via the socket to provide instructions on retrieving the generated information.
Data Retrieval. The client, now informed by the server via the socket, downloads the generated content. Once this operation is successfully completed, the client leaves the designated room.
Supported API calls
Refer to the API documentation that was released with your server.
Endpoint | Join room event name | Event to connect | Leave room event name |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
The returnZip
query parameter
The process API calls support a synchronous version (i.e., no use of sockets).
Setting the query parameter returnZip
for these calls to true will return the ZIP file.
Sample code
The example below shows the C# pseudo-code and uses the SocketIOClient. It contains a RigiSocket class and shows how to use it.
using SocketIOClient; using System; using System.Dynamic; using System.Text.Json; using System.Threading;
public class RigiSocket { public RigiSocket(...) { dynamic dynamicObject = new ExpandoObject(); dynamicObject.token = <token>>; dynamicObject.withCredentials = true; SocketIOOptions options = new SocketIOOptions { Auth = dynamicObject, Transport = SocketIOClient.Transport.TransportProtocol.WebSocket }; _client = new SocketIOClient.SocketIO("https://<servername>.rigi.io", options); _client.OnConnected += async (sender, e) => { dynamic enterRoomObject = new ExpandoObject(); enterRoomObject.projectId = <projectId>; enterRoomObject.tenantId = <servername>_rigi_io; //Same as the server name, where dots are replaced with underscores await _client.EmitAsync(<enterRoomEventName>, enterRoomObject); }; _client.On(downloadReadyEvent, response => { //The response was received from the server with the download id. try { using (JsonDocument doc = JsonDocument.Parse(response.ToString())) { JsonElement root = doc.RootElement; _downloadId = root[0].GetProperty("downloadId").GetString(); } } catch(Exception e) { _downloadId = $"ERROR: {e.Message}"; } }); _client.ConnectAsync().GetAwaiter().GetResult(); } private void LeaveRoom() { _client.EmitAsync(<leaveRoomEventName>, _projectId).GetAwaiter().GetResult(); } public static string WaitForDownload(RigiSocket socket, int intervalMs=1000) { while (socket._downloadId == null) Thread.Sleep(intervalMs); socket.LeaveRoom(); int id; if (!int.TryParse(socket._downloadId, out id)) { Console.WriteLine(socket._downloadId); //The download was not successful (the download ID contains the error message) return null; } return socket._downloadId; } } }
The main program that uses the socket looks like this:
var socket = new RigiSocket(...); api.execute("api/process/targets", targetfolder, ...); string zipId = RigiSocket.WaitForDownload(socket); string generated = pseudoTask.DownloadZipId(zipId); //The ZIP is now in the target folder