Public/ps1/Sql/Get-LeftConnectRemoteJob.ps1

function Get-LeftConnectRemoteJob{
    
        $channelId = ""
        $configuration = Get-LeftConnectSqlConfiguration
        if ($configuration.channelId) {
            $channelId = "?channelId=$($configuration.channelId)"
        }

        $deliverResult = "api/services/app/RemoteControl/SetDeliveries"
        $getTask= "api/services/app/RemoteControl/GetAssignment$channelId"
    

        #Get the job from the server
        $job = (Get-LeftConnectResult -request $getTask).result
        if (-not $job){
            return
        }
        Log("Receive the following job: $job")
        if ($job.Action -eq "SQL") {
            $result = Start-LeftConnectJobSql -taskInformation $job
            $result | Add-Member -MemberType NoteProperty -Name "Id" -value $job.Id -Force -ErrorAction SilentlyContinue
        } elseif ($job.Action -eq "FILE") {
            $result = Start-LeftConnectJobFile -taskInformation $job
            $result | Add-Member -MemberType NoteProperty -Name "Id" -value $job.Id -Force -ErrorAction SilentlyContinue
        } elseif ($job.Action -eq "SELFUPDATE") {
            $result = [PSCustomObject]@{
                success = $false
                message = Start-LeftConnectSelfUpdate
            }
        }else {
            $result = [PSCustomObject]@{
                success = $false
                message = ("There is no handler known for given action: " + $job.Action)
            }
        }

        # Send result to server
        $result | Add-Member -MemberType NoteProperty -Name "CreationDate" -value (Get-Date).ToString("o") 
        Get-LeftConnectResult -request $deliverResult -body  ($result | ConvertTo-Json)
        

        if ($result.success) {
            Remove-Variable result
            Get-LeftConnectRemoteJob
        }
        Remove-Variable result
}