View Source Lightning.WorkOrders.Query (Lightning v2.10.4)

Query functions for the Lightning.WorkOrders module.

Summary

Functions

Query to calculate the current state of a workorder.

Functions

@spec state_for(Lightning.Run.t()) :: Ecto.Query.t()

Query to calculate the current state of a workorder.

It takes a run, as the state is updated after each run is changed.

The logic is as follows:

  • All other Runs that are not in a finished state are considered first.
  • The current Run is unioned onto the unfinished runs with a null ordinality.
  • The runs are ordered by state in the following order started > available > claimed > null
  • The run states are then mapped to the workorder state enum, so available and claimed are both mapped to pending and started is mapped to running

The null ordinality ensures that the current run is always last in the ordering.