ExecRemoteGatewayJob
NOTE: Requires allowRemoteCodeExec = True on Smart Integration Connector Local Gateway. There is a defined default limit of 30 minutes for remote jobs to execute before the job is cancelled, and an overloaded version of ExecremoteGatewayJob exists allowing the timeout to be provided, but can never exceed 4 hours. This is not configurable and if this timeout is reached, the status returned shows the timeout. If the result is not obtained within five minutes after the job completes (using the GetRemoteGatewayJobStatus BRAPI), the remote results are purged to ensure that result objects reclaim server memory on the Smart Integration Service host.
NOTE: This is required to call back into GetRemoteJobStatus with the returned ID to obtain the result:
Here is a basic overview of invoking a remote job and displaying the returned remote Job ID in C#.
// ExecRemoteGatewayJob basic example
var GatewayName = ""; // Name of the Gateway
var SICFunctionName = ""; // Name of the SIC Function to run
var argTest = new object[2];
argTest[0] = 100; // Example first argument to SIC Function
argTest[1] = "test"; // Example second argument to SIC Function
// Invoking a OneStream SIC Function Business Rule as a remote job
var objRemoteRequestResultDto = BRApi.Utilities.ExecRemoteGatewayJob(si, SICFunctionName, argTest, GatewayName, String.Empty);
if (objRemoteRequestResultDto.RemoteResultStatus == RemoteMessageResultType.JobRunning)
{
// Logic to wait for job to complete
}
Here is the basic example in VB:
' ExecRemoteGatewayJob basic example
Dim GatewayName As String = "" ' Name of the Gateway
Dim SICFunctionName As String = "" ' Name of the SIC Function to run
Dim argTest(1) As Object
argTest(0) = 100 ' Example first argument to SIC Function
argTest(1) = "test" ' Example second argument to SIC Function
' Invoking a OneStream SIC Function Business Rule as a remote job
Dim objRemoteRequestResultDto As RemoteRequestResultDto = BRApi.Utilities.ExecRemoteGatewayJob(si, SICFunctionName, argTest, GatewayName, String.Empty)
If (objRemoteRequestResultDto.RemoteResultStatus = RemoteMessageResultType.JobRunning) Then
' Logic to wait for job to complete
End If
Here is the rule in C# to invoke a job, obtain the job ID, and 'poll' until completion:
// ExecRemoteGatewayJob with polling
var jobID = new Guid();
var GatewayName = ""; // Name of the Gateway
var SICFunctionName = ""; // Name of the SIC Function to run
// Invoke a long-running Job with a Smart Integration Function
var objRemoteRequestResultDto = BRApi.Utilities.ExecRemoteGatewayJob(si, GatewayName, null, SICFunctionName, String.Empty);
// If Successful, the status is retuned indicating the job is running with the job ID. Use this ID to interrogate if the job is compleed.
if (objRemoteRequestResultDto.RemoteResultStatus == RemoteMessageResultType.JobRunning)
{
jobID = objRemoteRequestResultDto.RequestJobID;
BRApi.ErrorLog.LogMessage(si, "Remote Job Queued and Running - JobID: " + jobID.ToString());
// Example waiting 20 seconds for job to complete
for (var loopControl = 0; loopControl < 10; loopControl++)
{
System.Threading.Thread.Sleep(2000);
var objJobStatus = BRApi.Utilities.GetRemoteGatewayJobStatus(si, jobID, GatewayName);
if (objJobStatus.RemoteJobState == RemoteJobState.Running)
{
BRApi.ErrorLog.LogMessage(si, "Remote Job Still running - JobID: " + jobID.ToString());
}
else if (objJobStatus.RemoteJobState == RemoteJobState.Completed)
{
// Checking the return type from the remote job
if (!(objJobStatus.RemoteJobResult.ResultSet is null))
{
var xfDT = new XFDataTable(si, objJobStatus.RemoteJobResult.ResultSet, null, 1000);
BRApi.ErrorLog.LogMessage(si, "Remote Job Completed - Datatable Returned - JobID: " + jobID.ToString());
return null;
}
else if (!(objJobStatus.RemoteJobResult.ResultDataSet is null))
{
var xfDT = new XFDataTable(si, objJobStatus.RemoteJobResult.ResultDataSet.Tables[0], null, 1000);
BRApi.ErrorLog.LogMessage(si, "Remote Job Completed - Dataset Returned - JobID: " + jobID.ToString());
return null;
}
else if (!(objJobStatus.RemoteJobResult.ResultDataCompressed is null))
{
BRApi.ErrorLog.LogMessage(si, "Remote Job Completed - Object Returned - JobID: " + jobID.ToString());
var value = CompressionHelper.InflateJsonObject<String>(si, objJobStatus.RemoteJobResult.ResultDataCompressed);
BRApi.ErrorLog.LogMessage(si, value);
return null;
}
}
else if (objJobStatus.RemoteJobState == RemoteJobState.JobNotFound)
{
BRApi.ErrorLog.LogMessage(si, "Remote Job Not Found - JobID: " + jobID.ToString());
return null;
}
else if (objJobStatus.RemoteJobState == RemoteJobState.RequestTimeOut)
{
BRApi.ErrorLog.LogMessage(si, "Remote Job Timed Out - JobID: " + jobID.ToString());
return null;
}
else if (objRemoteRequestResultDto.RemoteResultStatus == RemoteMessageResultType.Exception)
{
BRApi.ErrorLog.LogMessage(si, "Exception During Execution of Job: " + objRemoteRequestResultDto.RemoteException.ToString());
}
}
}
else
{
// Exception occurred immediately during compile/initial run
if (objRemoteRequestResultDto.RemoteResultStatus == RemoteMessageResultType.Exception)
{
BRApi.ErrorLog.LogMessage(si, "Exception Executing Job: " + objRemoteRequestResultDto.RemoteException.ToString());
}
else
{
BRApi.ErrorLog.LogMessage(si, "General Job Execution Error - State: " + objRemoteRequestResultDto.RemoteResultStatus.ToString());
}
}
return null;
Here is the rule in VB.NET to invoke a job, obtain the job ID, and 'poll' until completion:
' ExecRemoteGatewayJob with polling
Dim jobID As Guid
Dim GatewayName As String = "" ' Name of the Gateway
Dim SICFunctionName As String = "" ' Name of the SIC Function to run
' Invoke a long-running Job with a Smart Integration Function
Dim objRemoteRequestResultDto As RemoteRequestResultDto = BRApi.Utilities.ExecRemoteGatewayJob(si, GatewayName, Nothing, SICFunctionName, String.Empty)
' If Successful, the status is retuned indicating the job is running with the job ID. Use this ID to interrogate if the job is compleed.
If (objRemoteRequestResultDto.RemoteResultStatus = RemoteMessageResultType.JobRunning) Then
jobID = objRemoteRequestResultDto.RequestJobID
BRApi.ErrorLog.LogMessage(si, "Remote Job Queued and Running - JobID: " & jobID.ToString())
' Example waiting 20 seconds for job to complete
For loopControl = 0 To 10
System.Threading.Thread.Sleep(2000)
Dim objJobStatus As RemoteJobStatusResultDto = BRApi.Utilities.GetRemoteGatewayJobStatus(si, JobID, GatewayName)
If (objJobStatus.RemoteJobState = RemoteJobState.Running) Then
BRApi.ErrorLog.LogMessage(si, "Remote Job Still running - JobID: " & jobID.ToString())
Else If (objJobStatus.RemoteJobState = RemoteJobState.Completed)
' Checking the return type from the remote job
If (objJobStatus.RemoteJobResult.ResultSet IsNot Nothing) Then
Dim xfDT As XFDataTable = New XFDataTable(si, objJobStatus.RemoteJobResult.ResultSet, Nothing, 1000)
BRApi.ErrorLog.LogMessage(si, "Remote Job Completed - Datatable Returned - JobID: " & jobID.ToString())
Return Nothing
Else If (Not objJobStatus.RemoteJobResult.ResultDataSet Is Nothing) Then
Dim xfDT As XFDataTable = New XFDataTable(si,objJobStatus.RemoteJobResult.ResultDataSet.Tables(0), Nothing, 1000)
BRApi.ErrorLog.LogMessage(si, "Remote Job Completed - Dataset Returned - JobID: " & jobID.ToString())
Return Nothing
Else If objJobStatus.RemoteJobResult.ResultDataCompressed IsNot Nothing Then
BRApi.ErrorLog.LogMessage(si, "Remote Job Completed - Object Returned - JobID: " & jobID.ToString())
Dim value As String = CompressionHelper.InflateJsonObject(Of String)(si, objJobStatus.RemoteJobResult.ResultDataCompressed)
Brapi.ErrorLog.LogMessage(si, value)
Return Nothing
End If
Else If (objJobStatus.RemoteJobState = RemoteJobState.JobNotFound) Then
BRApi.ErrorLog.LogMessage(si, "Remote Job Not Found - JobID: " & jobID.ToString())
Return Nothing
Else If (objJobStatus.RemoteJobState = RemoteJobState.RequestTimeOut) Then
BRApi.ErrorLog.LogMessage(si, "Remote Job Timed Out - JobID: " & jobID.ToString())
Return Nothing
Else If (objRemoteRequestResultDto.RemoteResultStatus = RemoteMessageResultType.Exception) Then
BRApi.ErrorLog.LogMessage(si, "Exception During Exeuction of Job: " & objRemoteRequestResultDto.RemoteException.ToString())
End If
Next
Else
' Exception occurred immediately during compile/initial run
If (objRemoteRequestResultDto.RemoteResultStatus = RemoteMessageResultType.Exception) Then
BRApi.ErrorLog.LogMessage(si, "Exception Executing Job: " & objRemoteRequestResultDto.RemoteException.ToString())
Else
BRApi.ErrorLog.LogMessage(si, "General Job Execution Error - State: " & objRemoteRequestResultDto.RemoteResultStatus.ToString())
End If
End If
Return Nothing


