Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Access

...

Log Object

Code Block
languagepowershell
titleExample how to access order log objects
linenumberstrue
$logs = Get-JS7OrderHistory | Get-JS7OrderLog

...

An order log object carries a number of attributes as visible from the following console example:

Code Block
languagepowershell
titleExample of a order log object
linenumberstrue
PS /> $logs = Get-JS7OrderHistory | Get-JS7OrderLog
PS /> $logs[0]

controllerId : jobscheduler
historyId    : 3092
orderId      : #2022-03-06#P31960623406-cycle2
workflow     : /Examples.Windows/05_ScheduledExecution/jdwScheduledWorkflowCyclic
position     :
state        : @{severity=6; _text=SUCCESSFUL}
plannedTime  : 06.03.2022 09:12:00
startTime    : 06.03.2022 09:12:05
endTime      : 06.03.2022 09:12:32
log          : 2022-03-06 09:12:05.265+0100 [MAIN]    [OrderStarted]   id=#2022-03-06#P31960623406-cycle2, pos=0
               2022-03-06 09:12:05.377+0100 [MAIN]    [OrderProcessingStarted] id=#2022-03-06#P31960623406-cycle2, pos=0, Job=job1, Agent (url=https://apmacwin:4245,
               id=agent_001, time=2022-03-06 09:12:05.265+0100)

               2022-03-06 09:12:05.265+0100 [MAIN]    [Start] Job=job1, Agent (url=https://apmacwin:4245, id=agent_001)
               2022-03-06 09:12:05.955+0100 [STDOUT]  using workflow: jdwScheduledWorkflowCyclic
               running job1
               order scheduler for: 2022-03-06 08:12:00+0000
               job start date: 2022-03-06 08:12:05+0000
               2022-03-06 09:12:10.653+0100 [MAIN]    [End] [Success] returnCode=0

               2022-03-06 09:12:10.753+0100 [SUCCESS] [OrderProcessed] id=#2022-03-06#P31960623406-cycle2, pos=0, Job=job1, returnCode=0
               2022-03-06 09:12:10.669+0100 [DETAIL]  [OrderForked]    id=#2022-03-06#P31960623406-cycle2, pos=1
               2022-03-06 09:12:10.669+0100 [DETAIL]  [OrderStarted]   id=#2022-03-06#P31960623406-cycle2|branch1, pos=1/branch1:0
               2022-03-06 09:12:10.669+0100 [DETAIL]  [OrderStarted]   id=#2022-03-06#P31960623406-cycle2|branch2, pos=1/branch2:0
               2022-03-06 09:12:10.753+0100 [MAIN]    [OrderProcessingStarted] id=#2022-03-06#P31960623406-cycle2|branch1, pos=1/fork+branch1:0, Job=job2_1a, Agent
               (url=https://apmacwin:4245, id=agent_001, time=2022-03-06 09:12:10.669+0100)

               2022-03-06 09:12:10.669+0100 [MAIN]    [Start] Job=job2_1a, Agent (url=https://apmacwin:4245, id=agent_001)
               2022-03-06 09:12:11.306+0100 [STDOUT]  using workflow: jdwScheduledWorkflowCyclic
               running job2_1a
               order scheduler for: 2022-03-06 08:12:00+0000
               job start date: 2022-03-06 08:12:10+0000
               2022-03-06 09:12:16.098+0100 [MAIN]    [End] [Success] returnCode=0

Write

...

Log to File

Code Block
languagepowershell
titleExample how to write order logs to a common log file
linenumberstrue
Get-JS7OrderHistory | Get-JS7OrderLog | Out-File /tmp/history/orders.log -Encoding Unicode

...

A workflow is created that runs the above commands in a cycle. The workflow operates 24/7 and writes task order logs to files.

Download: pdwOrderLogsToFiles.workflow.json

...

Code Block
languagepowershell
titleExample for job get-history-taskorder-logs
linenumberstrue
#!/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

    # serialize and base64 encode 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

...

Code Block
languagepowershell
titleExample for job write-taskorder-logs-to-files
linenumberstrue
#!/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'; 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 ))

    # forward a variable for the object
    "lastHistoryEncoded=$lastHistoryEncoded" | Out-File $env:JS7_RETURN_VALUES -Append

Disconnect-JS7

...

  • Lines 1, 4: Same explanations as for the previous job.
  • Lines 7,8: The History ID of the last processing of this job is picked up from an environment variable that is assigned the workflow variable previously serialized and base64-encoded.
    • Image Modified

  • 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. 

...