...
Wait for completion of a temporary order
The following sample show explains how to wait for completion of an order:
Code Block | ||||
---|---|---|---|---|
| ||||
Import-Module JobScheduler UseConnect-JobSchedulerMasterJobScheduler http://localhost:44444446 echo "begin of test script" $order = Add-JobSchedulerOrder -JobChain /some_path/some_job_chain While ( ( $order | Get-JobSchedulerOrder -NoCache ).StartTimevolatile.nextStartTime ) { Start-Sleep -Seconds 10 } $orderHistory = $order | Get-JobSchedulerOrder -JobSchedulerOrderHistoryWithHistory echo "order $($orderHistory.OrderOrderId) completed with state '$($orderHistory.State)' at '$($orderHistory.EndTime.volatile.processingState._text)'" echo "end of test script" |
...
- Line 1: The
Import-Module
statement is used if the JobScheduler CLI module is not loaded from a profileLine 2: TheUse-JobSchedulerMaster
cmdlet is used for standalone scripts only. It should not be used with PowerShell Jobs. - Line 6: Adds a temporary ad hoc order to the specified job chain, see
Add-JobSchedulerOrder
.- The order identification is not specified but is generated by the JobScheduler Master.
- The resulting
$order
object contains the order identification.
- Line 7 - 10: Repeated checks are executed in a loop to verify if the order is completed.
- The newly added order is piped to the
Get-JobSchedulerOrder
cmdlet that returns an object with aStartTime
nextStartTime
property should the order still be running. - A sleep interval reduces the frequency of checks for completion of the current order.
- The newly added order is piped to the
- Line 12: Permanent orders are permanently available from the JobScheduler memory. Temporary ad hoc orders are removed from the JobScheduler memory after completion. Therefore the temporary ad hoc order is retrieved from the order history instead of the JobScheduler memory.
- Line 13: The order history provides information about the order's end time and end state that can be used to identify successful or failed execution.
...
Code Block | ||||
---|---|---|---|---|
| ||||
$jobScript = { Param ( [Uri] $masterUrl$url, [string] $jobChain, [int] $pollInterval=10 ) Import-Module JobScheduler if ( $masterUrl$url ) { $js = UseConnect-JobSchedulerMasterJobScheduler $masterUrl$url } $order = Add-JobSchedulerOrder -JobChain $jobChain While ( ( $order | Get-JobSchedulerOrder -NoCache ).StartTimenextStartTime ) { Start-Sleep -Seconds $pollInterval } $order | Get-JobSchedulerOrderHistoryJobSchedulerOrder -WithHistory } echo "begin of test script" $jobs = @() $jobs += Start-Job -ScriptBlock $jobScript -Argumentlist localhost:44444446,/some_path/some_job_chain $jobs += Start-Job -ScriptBlock $jobScript -Argumentlist localhost:44444446,/some_path/some_other_job_chain $orderHistory = $jobs | Wait-Job | Receive-Job for( $i=0; $i -lt $orderHistory.length; $i++ ) { echo "order '$($orderHistory[$i].idorderId)' completed with state '$($orderHistory[$i].State)' at '$($orderHistory[$i].EndTime.volatile.processingState._text)'" } echo "end of test script" |
...