Delen via


Defining Scheduled Rules

If your application supports scheduled subscriptions, you must define at least one scheduled rule.

Scheduled rules are named sets of one or more Transact-SQL queries that create notifications for scheduled subscriptions. Optionally, scheduled rules manipulate the data in subscription chronicles. Scheduled rules run during each quantum and evaluate only the subscriptions whose scheduled time for evaluation is in that quantum.

Note

The exact timing for firing scheduled rules depends on the quantum duration.

Each subscription class can contain one or more scheduled rules. However, you cannot specify rule firing order between scheduled rules. Scheduled rules can fire in any order.

Scheduled Rule Processing

Scheduled subscriptions generate their related notifications at scheduled times, which are typically specified by the subscriber when creating the subscription. Notification Services uses the following process to generate notifications from scheduled rules:

  1. Events arrive.
  2. Notification Services creates one event batch per event class, and then inserts each event batch into its respective event table.
  3. Notification Services runs the event chronicle rules for each event class, which updates event chronicles.
  4. Notification Services fires scheduled rules, and evaluates only those subscriptions due to be processed. Scheduled rules operate against event chronicles, not against event class views that only contain current event batches.
  5. The scheduled rules insert the resulting notifications into notification tables; this data is used to build and distribute notifications.

Because notifications are generated only at scheduled times, scheduled rules are good for periodic information updates. Daily weather forecasts and weekly portfolio reports are examples of applications that should use scheduled rules.

Defining a Scheduled Rule

A scheduled rule is part of a subscription class. When you define a subscription class, you must define at least one rule (scheduled or event-driven). To define a scheduled rule, you create a scheduled rule item. You then must provide a name, an action to perform, and a time-out value for the action.

To define a scheduled rule

Naming a Scheduled Rule

Each scheduled rule must have a name that is unique within the application. This name is used to identify each rule for administrative purposes.

To name a scheduled rule
  • If you are defining a scheduled rule through XML, define the scheduled rule name using the RuleName Element for ScheduledRule (ADF).
  • If you are defining a scheduled rule programmatically, define the scheduled rule name in the SubscriptionScheduledRule class (NMO).
  • If you are defining a scheduled rule with a condition action programmatically, define a scheduled name using the SubscriptionConditionScheduledRule class (NMO).

Defining an Action or Condition Action

An action is the query that Notification Services runs each time it fires the rule. Subscription rules can contain simple actions and more complex condition actions:

  • An action contains a Transact-SQL query used to generate notifications based on matches between subscription fields and event fields. When subscribers create subscriptions, they define parameters for the predefined query. For information about defining simple actions, see Defining Actions.
  • A condition action also has a Transact-SQL query, but this query defines a view from which subscribers can define their subscriptions. Instead of providing parameters for a predefined query, subscribers select the fields they are interested in and then define their own conditions using a predetermined set of operators. For information about defining condition actions, see Defining Condition Actions.

Specifying a Time-out Value

The action time-out specifies the permitted length of time for statements in the action or condition action to complete. If the statements do not complete before the time-out occurs, Notification Services rolls back the transaction, marks the scheduled rule as failed, and writes an error to the event log.

To specify a time-out value

See Also

Concepts

Defining Event Rules
Defining Actions
Defining Condition Actions
Defining Subscription Rules
Defining Chronicles for an Event Class

Help and Information

Getting SQL Server 2005 Assistance