Lifecycles

OCS Lifecycles

Rather than hard-code explicit lifecycles for services, or for wallets, the OCS provides a powerful mechanism for the dynamic definition of lifecycles. A lifecycle may be applied to a service as a subscription on a wallet, or to a wallet itself.

Lifecycles allow operators to define whether a subscription is a once-off immediate application of buckets, a regular subscription or some other form of process driven wallet adjustment. Crucially, lifecycle changes may be triggered by external systems, or internally by the OCS in response to expiry events.

Each designed lifecycle is associated with a lifecycle class, which helps the OCS understand where the lifecycle may be applied, and what access the lifecycle state transition logic when accessing the OCS’s engine.

The OCS is supplied with three types of lifecycle classes:

Lifecycle Purposes
Account The wallet lifecycle class is used exclusively for wallet specific lifecycles.
Subscription The subscription lifecycle class is used for all OCS service subscriptions.
Annotation (Bucket) A lifecycle that can be applied to a bucket to trigger, eg, a notification prior to the bucket expiry.
Voucher See the voucher lifecycle page for more information.

To define a lifecycle, use the /resource/lifecycle endpoint and provide a name for the lifecycle, and which class it belongs to. The lifecycle will be associated with a service by the service itself.

A lifecycle is built from one or more states, and the transitions between states are defined also through the OCS API. A conceptual lifecycle may consist of multiple states and steps, including cycles within these (the OCS protects against infinite loops, including infinite loops made of multiple states).

Lifecycle State Example

Lifecycle State Diagram

Each voucher state consists of:

State Field Purposes
Name A name which is used to identify the state in state transitions. The name is crucial to match to state transition rules.
Action An embedded Javascript fragment to execute within the OCS’s Javascript engine when this state is entered. The Javascript action gives the OCS the logic to execute to perform the lifecycle action. This may include debiting the user wallet (using the OCS rating engine), deleting the subscription (or wallet) the lifecycle is attached to, applying buckets to the subscriber, or performing any other activity allowed by the Javascript engine.

To move between states, a lifecycle employs state transitions:

Lifecycle Transitions Diagram

Lifecycle Transition Example

Transitions are defined on each state within a lifecycle, and consist of one of three types of state transitions: