Page History
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/usr/bin/env pwsh Import-Module JS7 Connect-JS7 -Url http://root:root@localhost:4446 -Id Controller | Out-Null $lastHistory = Get-JS7OrderHistory -RelativeDateFrom -30m | Sort-Object -Property startTime # serializeforward anda base64variable encodefor the object $xmlLastHistory = [management.automation.psserializer]::Serialize( $lastHistory ) $lastHistoryEncoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes( $xmlLastHistory )) # forward a variable for the object "lastHistoryEncoded=$lastHistoryEncoded" | Out-File $env:JS7_RETURN_VALUES -Append Disconnect-JS7 |
Explanation:
"lastHistory=json:$($lastHistory | ConvertTo-Json -Compress)" | Out-File $env:JS7_RETURN_VALUES -Append
Disconnect-JS7 |
Explanation:
- Line 1: The shebang is required to identify PowerShell being the Line 1: The shebang is required to identify PowerShell being the interpreter of the script. The above example is for Unix, for Windows the first line of the job script should be replaced as follows:
Code Block language powershell title Example of shebang for PowerShell with Unix linenumbers true #!/usr/bin/env pwsh
Code Block language powershell title Example of shebang for PowerShell with Windows linenumbers true @@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof
- Line 4: The are a number of ways how to specify details for a JS7 connection, see JS7 - How to connect to JOC Cockpit using the PowerShell Module.
- The host and port are specific for a user's environment.
- The Controller ID is specified during installation of the Controller and defaults to
Controller
.
- Line 9-13: A workflow variable is created that carries the History ID of the latest entry list of order log objects returned by
the Get-JS7OrderHistory
cmdlet for which task logs should be created. This variable is in fact a PowerShell object that is serialized and base64-encoded for to JSON and prefixed with the stringjson:
for later use with the second job in the workflow.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/usr/bin/env pwsh Import-Module JS7 Connect-JS7 -Url http://root:root@localhost:4446 -Id Controller | Out-Null # bas64 decode and deserialize the object $xmlLastHistory = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String( $env:LAST_HISTORY_ENCODED )) $lastHistory = [System.Management.Automation.PSSerializer]::Deserialize( $xmlLastHistory ) Get-JS7OrderHistory -DateFrom $lastHistory[0].startTime | Tee-Object -Variable lastHistory | Get-JS7OrderLog | Select-Object @{name='path'; expression={ "/tmp/history/$(Get-Date $_.startTime -f 'yyyyMMdd-hhmmss')-$([io.path]::GetFileNameWithoutExtension($_.workflow))-$($_.orderId).order.log"}}, @{name='value http://root:root@localhost:4446 -Id Controller | Out-Null # restore object from json by a temporary file $lastHistory = ( (Get-Content $env:LAST_HISTORY_FILE).Substring(5) | ConvertFrom-Json ) Get-JS7OrderHistory -DateFrom $lastHistory[0].startTime | Tee-Object -Variable lastHistory | Get-JS7OrderLog | Select-Object @{name='path'; expression={ $_.log }} | Set-Content # serialize and base64 encode the object $xmlLastHistory = [management.automation.psserializer]::Serialize( $lastHistory ) $lastHistoryEncoded = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes( $xmlLastHistory ))"/tmp/$(Get-Date $_.startTime -f 'yyyyMMdd-hhmmss')-$([io.path]::GetFileNameWithoutExtension($_.workflow))-$($_.orderId).order.log"}}, @{name='value'; expression={ $_.log }} | Set-Content # forward a variable for the object "lastHistoryEncoded=$lastHistoryEncodedlastHistory=json:$($lastHistory | ConvertTo-Json -Compress)" | Out-File $env:JS7_RETURN_VALUES -Append Disconnect-JS7 |
...
- Lines 1, 4: Same explanations as for the previous job.
- Lines 7,86: The History ID variable holding the list of order log objects of the last processing of this job is picked up is restored from a temporary file that holds the JSON representation of the object. The temporary files is provided by the JS7 Agent and is referenced from an environment variable that is assigned the workflow variable previously serialized and base64-encodedlike this.
Line 10: When reading the order history then the variable carrying the History ID is updated and is forwarded to the workflow for next execution of the cycle.
...
Overview
Content Tools