Public/ps1/Sql/Get-LeftConnectRemoteJob.ps1

function Get-LeftConnectRemoteJob{
    param ($pipeline)   

        if ($pipeline -ne "Default") {
            $channelId = "?channelId=$($pipeline)"
        }

        $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 "START_PIPELINES") {
            $result = [PSCustomObject]@{
                success = $true
                message = Start-AllPipelines
            }
        } elseif ($job.Action -eq "GET_PIPELINES") {
            $result = [PSCustomObject]@{
                success = $true
                message = Get-AllPipelines
            }
        } elseif ($job.Action -eq "STOP_PIPELINES") {
            $result = [PSCustomObject]@{
                success = $true
                message = Stop-AllJobs
            }
        } elseif ($job.Action -eq "CREATE_PIPELINE") {
            $result = [PSCustomObject]@{
                success = $true
                message = Create-PipelineJob
            }
        } elseif ($job.Action -eq "SELFUPDATE") {
            $result = [PSCustomObject]@{
                success = $true
                message = Start-UpgradeLeftConnect
            }
        } 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
}