SECAs and Error/Failure Management

This is based on REV 1163468, and my interpretation of the code. I may have misunderstood something, so don't bet anything important on this document being correct.

In the first section I'll describe some general rules that apply most of the time. The second section will describe what happens in what order during a typical run, highlighting some exceptions to the general rules given in the first section. Sync and Async services are handled slightly differently, so I'll cover them separately. In the third section I'll list more exceptions to the rules given in the first section.

When I talk about the service chain, I am referring to the chain or list of services that may actually (attempt to) run when one service with SECAs is run. All services in the service chain, except the main one, are defined in action elements in SECAs. The order they run is determined primarily by the value of the event attribute for a SECA. See the Sync and ASync sections below for the order.

I am completely ignoring global-commit and global-rollback events, eca conditions, and set actions.

General Rules

Typical Run

The order of the items in the service chain and when errors/failures are checked differs slightly depending on whether the service was called sync or async. The two service chains are summarised below. In these chains, the word action refers to a service named in the action element of a seca for the relevant event, and the word event refers to the actual event. check signifies that any errors or failures so far admitted are noted, and the remaining services will be made aware of them.

Sync

For a Sync service, the service chain runs as follows:

  1. auth action
  2. check
  3. auth event
  4. in-validate action
  5. check
  6. validate event (skipped if any admitted errors or failures so far)
  7. invoke action
  8. check
  9. actual service run (skipped if any admitted errors or failures so far)
  10. check
  11. out-validate action
  12. validate event
  13. commit action
  14. check
  15. global-commit-post-run action
  16. release locks, end transactions, commit unless there has been an error, in which case rollback
  17. return action

The locations of the check are important when managing errors/failures. An admitted error or failure in a service will not affect later services until there's a check. For example, if the out-validate action service admits to an error or failure, the commit action will not alter its behaviour, as it will not be notified of the failure/error.

The comment "(skipped if any admitted errors or failures so far)" applies irrespective of the settings of run-on-error and run-on-failure.

ASync

For an Async service, the service chain is:

  1. auth action
  2. auth event
  3. in-validate action
  4. check
  5. validate event (skipped if any admitted errors or failures so far)
  6. submit service to JobManager (skipped if any admitted errors or failures so far)

The JobManager appears to eventually submit the service to the Sync code. Presumably this means auth and in-validate will be run a second time (unconfirmed).

Notice that unlike the Sync version, the ASync service chain does not have a check after the auth action.

Exceptions

See Also

There are several other documents that discuss SECAs in OfBiz. This document repeats some of the same information, but with a different slant aimed at understanding how to use run-on-error/run-on-failure/ignore-error/ignore-failure.

For further information on SECAs, try:

Don't make the mistake I did, and assume "the service" referred to in some of the above documents is the main service referred to in the eca tag. If you think of it as meaning "any service in the service chain" you will be closer to the truth.

Also refer to the relevant schema (service-eca.xsd) in OFBiz, for attributes not documented above.