Versions Compared

Key

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

...

Configuring Directory Watching

Find a sample implementation from the following chapters.

...

There is more than one way how to do it, a number of alternative implementations are possible.

Download

Download (upload .json): pdfWatchDirectoryEvents.workflow.json

...

The Cycle Instruction is an option that users apply who want to watch directories during certain business hours only.

The instruction allows to specify weekdayspecifying weekdays, month days etc. and the period during the day for which the job will be repeatedly executed.

Clicking the Cycle Instruction in the Configuration view displays the cycle in the right panel with from the property editor.


Clicking the period brings up the details of the cycle:

...

  • PowerShell is available for Windows servers by default.
    • Consider the shebang in the first line of the job that indicates the PowerShell version in use:
      • the string following string indicates use of powershell.exe from version 5.1:
        • @@setlocal enabledelayedexpansion & @@findstr/v "
        ^@@f
        • ^@@[fs].*&" "%~f0" | powershell.exe -
        &goto:eof
        • NonInteractive -Command - & exit !errorlevel!/b&
      • the following string indicates use of powershellpwsh.exe from version 5.1.the string 6 or 7:
        • @@setlocal enabledelayedexpansion & @@findstr/v "
        ^@@f
        • ^@@[fs].*&" "%~f0" |
        pwsh
        • powershell.exe
        -&goto:eof indicates use of pwsh.exe from version 6 or 7.
        • -NonInteractive -Command - & exit !errorlevel!/b&
  • PowerShell can be installed for Unix environments such as Linux and MacOS.
    • Consider to modify modifying the shebang in the first line of the job like this:
      • the string #!/usr/bin/env pwsh can be used assuming that pwsh is the binary of the PowerShell interpreter.

Running the Workflow

Adding an Order

In the Workflows view users can add an order to the workflow:

  • The workflow's action menu offers the Add Order operation.
  • Alternatively the Image Added icon can be used to add an order.

Image Added


Adding an order brings up the following popup window:

  • The popup window displays the list of required workflow variables. An order can be added only after values for required variables are specified.
  • Workflow variables equipped with a default value can be changed when clicking the Modify Variables link.

Image Added


When clicking the Modify Variables link the following popup window is displayed:

  • The popup window allows to specify values for all variables declared with the workflow.


Image Added


Monitoring Execution

When the order is added it will be displayed in the Workflows view

  • from a green bullet in the same row as the job that is executed.
  • from the History panel the Order ID is visible that can be clicked to open the order's log view window.

Image Added

Viewing the Order Log

The order log view window displays

  • information about the start time and the Agent used to execute the workflow,
  • information about workflow variables,
  • any output created by the job,
  • the contents of the monitor log that holds registered events.

Image Added

Adding a Schedule

If the workflow runs fine you can automate execution by adding a schedule, see JS7 - Schedules.

  • Assign the newly created workflow to your schedule.
  • The list of workflow variables will be displayed similarly to adding an ad hoc order.

Image Added


Using the Run-time button brings up the popup window to specify start time rules:

  • Adding a schedule requires to assign a working day calendar, see JS7 - Calendars and Schedules.
  • For the start time add a period with a single start at midnight of your time zone.
    • The workflow's Cycle Instruction will rule the point in time during the day when the order will start on the given days.
  • Optionally add a Restriction to limit execution of the workflow to certain days, for example Mon-Fri.

Image Added

Backup

Job Source Code

Find the full source code of the job:

...

  • The implemenation makes use of the
  • Lines 7 - 11: creates the FileSystemWatcher object
  • Lines 14 - 33: hold the script block to move files in case of events indicating creation of a file.
  • Lines 36 -38: hold the script block to log events in case of events not related to creation of a file.
  • Lines 41 - 44: subscribe to the related events and assign the respective script block
  • Lines 58 - 68: loops for the given period and interrupts in intervals to check for changes to the monitor log file.
  • Lines 71 - 72: unsubscribes from registered events and destroys the FileSystemWatcher object.