Versions Compared

Key

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

Table of Contents

Introduction

  • User Users might be interested to in automatically receive receiving reports about the daily plan that states what workflows are scheduled for what time.the JS7 - Daily Plan which list the scheduled workflows and the date and time when they are executed.
    • Such reports include similar information to that which is available in the JOC Cockpit's
    • The reports include the same information as available from the JOC Cockpit Daily Plan view.
    • The reports are provided as Excel® files similar to what is those which are available for export from the JOC Cockpit Daily Plan view.
  • The report These reports can be scheduled, for example on a daily basis or more frequently , to provide ongoing information about completed tasks and outstanding tasksorders and timed orders for workflow execution.

Report the Daily Plan from a Job

Daily Plan reports can be automated by by JS7 jobs. Two The following PowerShell modules are used for this purpose:

...

Find a sample report for download that includes the report with its Daily-Plan worksheetjobscheduler_reporting.xlsx

First Line of the Job

The only difference between platforms is the way how PowerShell is invoked with the first line of the job.

Code Block
languagebash
titleShebang for PowerShell Job with Unix
#!/usr/bin/env pwsh

...

Code Block
languagebash
titleShebang for PowerShell Job with Windows
@@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof

...

  • Credits for the Windows shebang replacement to How to run a PowerShell script within a Windows batch file.
  • If you consider this shebang replacement somewhat cryptic then add it to JS7 - Script Includes that are easily referenced from a shell job, for example by using ##!include pwsh.
  • The PowerShell executable pwsh.exe is available starting from PowerShell 6.0. PowerShell releases 5.x use the executable powershell.exe that can be specified accordingly with the shebang.

Job Implementation

Please consider note that the job listed below job is an example that which has to be adjusted modified for your environment.

Download (.json upload)jdDailyPlanReport.workflow.json

...

Code Block
languagepowershell
titleDaily Plan Report Job
linenumberstrue
@@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof

Import-Module ImportExcel
Import-Module JS7

$credentials = ( New-Object -typename System.Management.Automation.PSCredential -ArgumentList 'root', ( 'root' | ConvertTo-SecureString -AsPlainText -Force) )
Connect-JS7 -Url $env:JS7_JOC_URL -Credentials $credentials -Id $env:JS7_CONTROLLER_ID | Out-Null

# start mode mapping
$startModes = @{"0"="single start"; "1"="repeat start-start"; "2"="repeat end-start"}

# Dates in local time zone, output includes local date format
Get-JS7DailyPlanOrder -Timezone (Get-Timezone) `
                |  Select-Object -Property @{name="Workflow"; expression={$_.workflowPath}}, `
                                           @{name="Order ID"; expression={$_.orderId}}, `
                                           @{name="Status"; expression={$_.state._text}}, `
                                           @{name="Order Name"; expression={$_.orderName}}, `
                                           @{name="Late"; expression={$_.late}}, `
                                           @{name="Start Type"; expression={ $startModes["$($_.startMode)"] }}, `
                                           @{name="Repeat Interval"; expression={$_.period.repeat}}, `
                                           @{name="Planned Start Time"; expression={ Get-Date $_.plannedStartTime }}, `
                                           @{name="Expected End Time"; expression={ Get-Date $_.expectedEndTime }}, `
                                           @{name="Expected Duration (sec.)"; expression={ (New-Timespan -Start "$($_.plannedStartTime)" -End "$($_.expectedEndTime)").Seconds }}, `
                                           @{name="Start Time"; expression={ Get-Date $_.startTime }}, `
                                           @{name="End Time"; expression={ Get-Date $_.endTime }}, `
                                           @{name="Duration (sec.)"; expression={ (New-Timespan -Start "$($_.startTime)" -End "$($_.endTime)").Seconds }} `
                | Export-Excel -Path /tmp/jobscheduler_reporting.xlsx -WorksheetName "Daily-Plan" -ClearSheet
				
Write-Output ".. report created: /tmp/jobscheduler_reporting.xlsxlsx"

Explanations

  • Line 2-31: The job is executed with a Windows Agent that is assigned by a process class. The job is of type "powershell" and will use the PowerShell version provided with the server.and uses the PowerShell shebang for Windows, as explained above.
  • Line 3-4Line 4-5: The required PowerShell modules are imported. They could be installed with at any location in the file system
  • Line 6-7: The Connect-JS7 cmdlet is used to authenticate with the JOC Cockpit JS7 REST Web Service API. The required URL and credentials are specified in a PowerShell profile, see PowerShell CLI 1.2 - Use Cases - Credentials Managementarguments for -Url , -Credentials and -Id can specified in a number of ways:
  • Line 10: For better readability of the report the start types of jobs are mapped to a textual representation (single start, cyclic start etc.).
  • Line 13: The Get-JS7DailyPlanOrder cmdlet is called invoked
    • with the parameter -Timezone parameter to specify to which time zone date values in the report should be converted to. The parameter value -Timezone (Get-Timezone) parameter value specifies that the time zone of the Agent's server is used. Otherwise specify the desired time zone e.g. can be specified, for example like this: -Timezone (Get-Timezone -Id 'GMT Standard Time'). Without using
    • When this parameter is not specified then any date values are will be stored in the report as UTC dates to the report.
    • optionally with additional parameters, e.g. for example to specify the date or date for range which the report is created  being created for. A value -DateTo (Get-Date -Hour 0 -Minute 0 -Second 0).AddDays(8).ToUniversalTime()RelativeDateTo +7d specifies that the report should cover the next 7 days (until midnight). Keep in mind that dates have to be specified for the UTC time zone. Without this parameter the report will be created for the next day.
    • see the Get-JS7DailyPlanOrder cmdlet  cmdlet for a full parameter reference.
  • Line 14-26: From the output of the Get-JS7DailyPlanOrder cmdlet a number of properties are selected and and are specified for the sequence in which they should occur in the report. 
    • To add more speaking appropriate column headers the property names are mapped to a more readable textual representation.
    • Consider Note the handling of date formats in line 21, 22 and 24, -25. Use of the Get-Date cmdlet converts the output format of dates (not the time zone) to the default format that is in place on the Agent's server. Without using the Get-Date cmdlet any date values will be stored to in the report in ISO format, e.g. 2020-12-31 10:11:12+02:00 for a date in the European central time zone that which is UTC+1 in winter time and UTC+2 in summer time.
    • Lines 23, 26 introduce a new property, a calculated duration. From This is the difference in seconds between the start time and end time values of a planned start and optionally of a past start the difference in seconds , which is calculated and is forwarded to the report.
  • Line 27: The list of properties per daily plan Daily Plan item is piped to the Export-Excel cmdlet that which is available with the ImportExcel PowerShell Module. The report file name is specified and optionally the worksheet. For a full list of parameters see the ImportExcel PowerShell Module.

Explanation:

  • Basically the same explanation as for the Windows version of the job applies.
  • Line 1: The PowerShell has to be invoked with pwsh. Consider that any subsequent PowerShell commands are quoted within a string that starts with line 3 and that ends with line 29. 
    • As the string is using a single quote all subsequent PowerShell commands make use of double quotes when required.
    • You could apply a different quoting style, however, quotes have to be consistent.
  • Line 3: As an example a PowerShell profile is invoked that provides the variables for URL and credentials to access the JS7 REST Web Service API. Such profiles can be stored in different locations and can be invoked automatically by pwsh on start-up.