Introduction
The JS7 offers File Watching out-of-the-box.
- JS7 Agents can be used to watch for incoming files from specific directories.
- For each incoming file a file order is created that is passed to the related workflow.
- Users are in charge of (re)moving files from the incoming directories.
File and Directory Watching
There is a fundamental difference between both concepts:
- File Watching is about watching for incoming files from a directory.
- The JS7 will create a file order for each incoming file.
- File Watching is performed by JS7 Agents per directory, for details see JS7 - File Watching.
- Directory Watching is about watching for changes to a directory.
- Changes include the situation when a file or sub-directory is added, changed, renamed or deleted.
- For each change an event is raised that can be used to trigger actions.
- Directory Watching is performed by tools and frameworks close to the Operating System such as iNotify, Java and .Net.
Directory Watching
Find a sample implementation from the following chapters.
Download (upload .json): pdfWatchDirectoryEvents.workflow.json
Workflow
The workflow includes a single job that implements Directory Watching.
Explanation:
- The job is included in a JS7 - Cycle Instruction. The purpose of this instruction is to manage periods for which Directory Watching should be performed.
- The workflow makes use of a number of variables.
- Workflow variables without default value have to be specified when adding orders to the workflow.
move_destination
: specifies the target directory to which incoming files will be moved.monitor_path
: specifies the source directory that is watched for incoming files
- Workflow variables with default values can be omitted when adding orders to the workflow.
monitor_filter
: specifies a wildcard expression to select files, for example a filter*.csv
will limit files in consideration to this extension.monitor_subdirectories
: specifiestrue
if sub-directories should be considered and otherwisefalse
.monitor_log_file
: specifies the log file for events.monitor_period
: specifies the duration of job execution in seconds. If the specified duration is exceeded then the job will terminate and will be restated by the Cycle Instruction. This guarantees that the file watcher is renewed and that any sub-directories that might have become inaccessible, for example from a remote share that is rebooted, will be registered with the next job run.monitor_interval
: specifies the interval in seconds between checks of themonitor_log_file
for changes.monitor_steady
: specifies the number of seconds that an incoming file is waited for to check that the file size is unchanged and the file can be considered stable.
- Workflow variables without default value have to be specified when adding orders to the workflow.
Cycle
The Cycle Instruction is an option that users apply who want to watch directories during certain business hours only.
The instruction allows to specify weekday, month days etc. and the period during which the job will be repeatedly executed.
Clicking the Cycle Instruction in the Configuration view displays the cycle in the right panel with the property editor.
Clicking the period brings up the details of the cycle:
Job
The job is implemented with PowerShell:
- 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
@@findstr/v "^@@f.*&" "%~f0"|powershell.exe -&goto:eof
indicates use ofpowershell.exe
from version 5.1. - the string
@@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof
indicates use ofpwsh.exe
from version 6 or 7.
- the string
- Consider the shebang in the first line of the job that indicates the PowerShell version in use:
- PowerShell can be installed for Unix environments such as Linux and MacOS.
- Consider to modify the shebang in the first line of the job like this:
- the string
#!/usr/bin/env pwsh
can be used assuming thatpwsh
is the binary of the PowerShell interpreter.
- the string
- Consider to modify the shebang in the first line of the job like this:
Find the full source code of the job:
Explanation:
- x