Event Reliability

The Problem

Loopback offers a number of Operation Hooks which enable you to intercept actions that occur on models.

Say a model was created or modified and we expect this to trigger some other action in the “after save” of the model.

If the update failed for whatever reason before it actually was stored in the database, we could easily detect this and reapply the update which would trigger the action.

However, if something failed in the “after save”, the object would appear updated and the action may never have been triggered.

The Solution

oeCloud Framework has added replay ability to the “after save”, which will assure the execution of those actions.

How to implement

Any object extended from BaseEntity will have this capability.

When is it applied

If any error is returned from within the “after save”, it will be executed again (from a background process), unless you set “retriable” property on the error object to false.

Proper Use Case

Ideally, this functionality is meant to be used when we would be trying to comminicate with an external source, such as a Database, that could temporarily be unavailable.

Pay Attention

To guarantee safe exectution of your observer, the observer itself should be idempotent - meaning different executions with the same arguments should result with the same output.