Event-based Scheduling

A scheduled job can work with events in two ways: A job can wait to run until an event is triggered or it can be the one that triggers events upon success or failure of itself. Jobs using events keep the same scheduling rules with respect to dates and times and reoccurrences; however, the start dates don't imply when the report starts processing, but rather when the report starts listening for the event. The most common scenario around events is needing to wait for a data warehouse load to complete before a job is run. There are several steps involved in setting up this scenario. First, an event needs to be created. This can be done via the Crystal Management Console or programmatically. The next chapter discusses how to create events programmatically. Next, use the ISchedulingInfo to set up the preferred date/time and reoccurrence settings. Then call the getDependencies method to obtain the IEvents interface. Finally, call the add method passing in the ID of the event object. This object is found in the SI_SYSTEMOBJECTS table like the business calendars. The following code snippet shows scheduling a report to start listening for an event called “Data Warehouse Load” at 2 a.m. every morning for November:

IInfoObjects eventResults = iStore.query("SELECT SI_ID FROM CI_SYSTEMOBJECTS" +
    " WHERE SI_NAME='Data Warehouse Load'");
IInfoObject event = (IInfoObject) eventResults.get(0);
ISchedulingInfo sched = report.getSchedulingInfo();
IEvents events = sched.getDependencies();
events.add(event.getID());
sched.setType(CeScheduleType.DAILY);
SimpleDateFormat dateFormat = new SimpleDateFormat();
Date beginDate = dateFormat.parse("11/01/2004 02:00 AM");
Date endDate = dateFormat.parse("11/30/2004 02:00 AM");
sched.setBeginDate(beginDate);
sched.setEndDate(endDate);
iStore.schedule(results);

In this case, the report is waiting for the data warehouse load event to be triggered, but perhaps there are multiple steps to this load and multiple events. This is fine because a scheduled report can listen for multiple events to be fired. Simply call the IEvents add method for each event that needs to be listened for.

The other way to work with event-based scheduling is to have a completed report job trigger an event either on success or completion. That event could in turn kick off other actions in the system. From a programmatic standpoint, this works exactly the same way as event dependencies except, instead of calling the ISchedulingInfo's getDependencies method, the getDependants method is called. Keep in mind that events added to a schedule's dependants can only be schedule events, not file or custom events. The following code snippet schedules a report but triggers a Weekly Report Completed event upon successful completion:

IInfoObjects eventResults = iStore.query("SELECT SI_ID FROM CI_SYSTEMOBJECTS" +
    " WHERE SI_NAME='Weekly Report Completed'");
IInfoObject event = (IInfoObject) eventResults.get(0);
ISchedulingInfo sched = report.getSchedulingInfo();
IEvents events = sched.getDependants();
events.add(event.getID());
sched.setType(CeScheduleType.WEEKLY);
SimpleDateFormat dateFormat = new SimpleDateFormat();
Date beginDate = dateFormat.parse("06/01/2004 08:00 AM");
Date endDate = dateFormat.parse("06/15/2004 08:00 AM");
sched.setBeginDate(beginDate);
sched.setEndDate(endDate);
iStore.schedule(results) ;
					

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.142.166