Creating an Event Based Job Definition

After looking at the scheduler trigger, the other triggers have something in common. They are all event-based triggers, which means they all trigger when something external to JobServer.NET occurs and the trigger detect this change. Thus, some external event causes these types of triggers to have a job start executing.

One of the most popular of the event-based triggers is the FileWatcher trigger. This trigger can watch for file activity in a specified folder and respond to file changes in it. This can be very handy for numerous situations. Maybe you want to take files that are dropped into a folder and automatically compress them into a ZIP file. Or maybe you have some legacy system that can generate a bunch of files to a folder, but you need a way to email them out automatically to a supplier or vendor for processing.

To start with creating an example FileWatcher, create a new job definition by right clicking your server and selecting New Job. When the new job form appears, change the Name to "Copy Files to Other Department". Then go to the Trigger field and select FileWatcher. When the parameters dialog for FileWatcher appears, go to the Folder path to watch setting and add the value "C:\Temp\JobServer\Pickup". Then in the Trigger actions field, select the All option. You can now click the Save button to finish creating the trigger.

Next create a step for this job by clicking the New Step button. In the Module field, select the [Files] Copy Move module. In the Name field, change the text to "Copy files from pickup to other dept". Then in the parameters, we want to specify the File source as the example folder "C:\Temp\JobServer\Pickup". Then select the Copy option for the Copy or Move parameter. And finally, you want to specify the Destination folder as "C:\Temp\JobServer\OtherDept" before you click the Save button to complete the settings for this step.

And finally, click the Save button on the job definition to create the new job. Once you do this, the job is now active and any files you place into the Pickup folder you created, will be immediately be copied to the OtherDept folder. This functionality works with files on local storage, or on network paths. The only requirement is that the JobServer.NET service must have permissions to the filesystem the files and folders are stored on.

Now with the job defined and enabled, you can test out this event based job definition by putting some files into the folder it is watching, the source folder or Pickup folder as we have named it in the example steps above. Then we watch as the job gets triggered and executes by copying the files we send it to the configured target folder, named OtherDept in the example steps above. This will happen pretty fast, so you will have to pay close attention to see it happen. To try it, we arranged a few file explorer windows to make it easy to view all of them at once. The one on the bottom contains a few example files we are going to drag into the Pickup folder.

To test the newly configured job definition, you want to copy some files into the source folder you configured above. To do this, copy some files from another location and paste them into the "Pickup" folder that you defined as the source folder.

After the job executes, you see the files dropped into the source folder (Pickup) are automatically detected by the JobServer with the FileWatcher trigger and they are copied to the target folder (OtherDept).