Skip to Content

File Event based Scheduling in DCP

Important information

The below solution is a sample application, to enable Desktop Intelligence Compatibility Pack users to do “File Event Based Scheduling”, this is an attempt to provide a direction on how to go about executing file event based scheduling for Desktop Intelligence Documents.

Users are free to use the sample exe and the source code and customize it to suit their needs, at their own risk. SAP does not support this sample application.

The sample application is written in Visual Basic using Windows Task Scheduler APIs and File watchers available within Microsoft’s API Library.

Detailed information about Task Scheduler development is available at

Information about developing applications in Visual Basic using Visual studio IDE is available at

To know more about Desktop Intelligence Compatibility Pack, you can commence here

Event Based scheduling for Desktop Intelligence

To know more about event based scheduling, please refer to the admin guides at http://help.sap.com/boall_en/

The sample application is available for download with SAP NOTE # 1911271 from https://service.sap.com/sap/support/notes/1911271

In the sample application: we are providing an example how to achieve File based Events to trigger tasks.

The Sample Application consists of two exes

  • File_watcher.exe and
  • TaskTriggerSwitch.exe

 

Step-by-step approach

  1. Copy the sample exes File_watcher.exe, TaskTriggerSwitch.exe to the folder C:\ProgramData

        Since C:\ProgramData is a hidden folder, you may not see the folder sometimes. Enable viewing Hidden folders to find the folder

            

Note: This step is important to enable event based scheduling when the user has logged off from the system

2.      Check for the environment variable ‘ALLUSERSPROFILE’

  The environment variable ‘ALLUSERSPROFILE’ is usually set to C:\ProgramData
  To verify, type ‘set’ in command prompt and validate if the variable ‘ALLUSERSPROFILE’ points to C:\ProgramData

 

     If the foresaid environment variable doesn’t exist, Create the same

       

  It is recommended to set the properties of “File_watcher.exe” to run it as an administrator (as the exe would be accessing Task Scheduler service, creating files etc.)

3.     Go to “File_watcher.exe”  properties->Advanced->Check Run as administrator, so that you need not do -> Run as administrator every time

 

4.     Run “File_watcher.exe” whenever you intend to create a new File event

            

  

5.     Click Yes

          On start of “File_watcher.exe”,  creates two tasks in the task scheduler

    1. DCP Event Boot Trigger
    2. DCP Event Logoff Trigger

The above tasks are important for automatically recreating the file watcher’s which would have been closed, during a Reboot or logoff on the machine.

These tasks are created whenever File_watcher.exe is run. If they already exist, they are overwritten. If they are manually deleted, they’ll get recreated the next time you run the File_watcher.exe.

If the user deletes these two tasks and reboots or logs off the machine, the all the events will NOT be recreated.

“File_watcher.exe” requires two inputs from the user

    1. File to monitor: You will be prompted with an Input box. Enter the full path to the file you want to monitor for changes

         

Note: It’s assumed that you have already created a scheduled task via Desktop Intelligence using DCP Scheduling feature and your task is listed in the Windows Task Scheduler.

Make sure the ‘Hidden’ property is ‘unchecked’ in the properties of the task which is being chosen for adding file event. By default all tasks created are ‘Hidden’ to avoid other logged on users in the machine editing tasks not owned by them. If the tasks are hidden they won’t be shown in the next window for further actions.

Follow the below diagram to unhide the task.

7.    Task to associate the Event to: Choose the tasks you want to associate to this file changes. Enter their serials as comma separated values in the input box

        

Note: It’s assumed that you have already created a scheduled task via Desktop Intelligence using DCP Scheduling feature and your task is listed in the Windows Task Scheduler.

  1. Click OK
  2. The command line displays the following information
    1. The list of tasks that get triggered on this file event
    2. The full path of the file that is being monitored

               Enter STOP in the command line to stop monitoring the file

 

8.     In the Task Scheduler UI, you can see that the tasks chosen have multiple triggers now. They will be triggered whenever the file is present on schedule run or created when waiting for run

 

  1. Running the file watchers during logoff or after restart

                The triggers for this are already created with names DCP Event Boot Trigger and DCP Event Logoff Trigger

Tip: You can always check the Event_config.txt file anytime for the file under monitor and tasks associated with it

Suggestions

  1. Once the tasks are modified, if you want to bring them back to their original state wherein they were purely time based schedules, go to the appropriate task in the task scheduler and delete the newly created event trigger and the new action which points to TaskTriggerSwitch.exe

2.    To see which task is associated with which file event, go to the task->properties->triggers->custom event trigger->custom event filter. The xpath query has a field called EventData which points to the respective file

3. During logged off state, the file_watcher.exe cannot run with a UI. So, it runs in the background. It can be seen in the Task manager and the associated files under monitor are under the column “Command line”

 

Summary:

Creating the File event

When you define a file-based event, you specify a filename that should be monitored. When the file appears, appropriate event should be triggered. For instance, you might want to make some reports dependent upon the regular file output of other programs or scripts.

To achieve this, users are advised to run the File Watcher program on the local machine.

The exe does the following actions:

  1. Takes the file path to monitor as input and runs minimized
  2. Takes in the tasks to be triggered on the above mentioned file creation
  3. Modifies the tasks chosen by adding a new event trigger and a new action
  4. Updates the Windows event server with a user-tailored event when the file creation happens
    1. Note: User-tailored event will be an event generated as per the user’s needs. It consists of three integral parts: Event source name, Event Log Type, Event Id
  5. Tasks will trigger on the scheduled time when the file is present. Else, it waits for the file creation till the next recurrence

Triggering schedule on File Event

Note: It’s assumed that you have already created a scheduled task via Desktop Intelligence using DCP Scheduling feature and your task is listed in the Windows Task Scheduler.

The task is already present which contains a time trigger. On running the sample application File_watcher.exe and adding the task to be modified following changes happen to the task

  1. The time trigger will remain enabled and a new event trigger will be added in the triggers list. The task status will now be shown as ‘Multiple triggers defined’.
  2. A new action which will be pointed to call the TaskTriggerSwitch.exe. This exe when run will switch between the two triggers. So the task will either wait for file creation with the event trigger alone enabled or wait for its time to run with time trigger alone enabled.
  3. The File event will be added as new trigger whose activation and expiry time will be same as the time trigger. It has a custom event filter which monitors the Windows event viewer for specific event source, event id and event data. Whenever the file is created, the corresponding event is added to the Windows events.
  4. The file watchers are exes which should always be running to monitor the file creation event. So normally during logoff/system reboot, the exes are killed. To spawn them again automatically, there are two tasks created
    1. DCP Event Boot Trigger
    2. DCP Event Logoff Trigger

These triggers will run a batch file called trigger_watchers.bat which recreates all those killed file watcher exes at the time of log-off and machine restart

These tasks are created whenever File_watcher.exe is run. If they are already present, they are overwritten. So even if you delete them manually, they’ll get recreated once you run the File_watcher.exe

In the folder C:\ProgramData, there should be four files present always

  1. File_watcher.exe – main application which does file watching
  2. TaskTriggerSwitch.exe – toggles the event trigger between enabled and disabled states to make it wait for file creation event
  3. Event_config.txt – contains the file path which is under monitor and the tasks which will be triggered on creation of this file
  4. trigger_Watchers.bat – contains batch command to trigger the file events during logoff or restart
Tags:
Former Member

No comments