Lightning.WorkOrders.Query (Lightning v2.19.0-pre)
View SourceQuery 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 > claimed > available > null - The run states are then mapped to the workorder state enum:
availableis mapped topending(the only run state Lightning can still cancel atomically), whileclaimedandstartedare both mapped torunning.
The
nullordinality ensures that the current run is always last in the ordering.