...

  1. Scheduled-style mechanism

    This group of approaches is based on periodic scanning of all saved pieces and determining the status of poline on this basis. A typical algorithm for such mechanism might look as shown on Figure 1.

    Figure 1 - A general algorithm of mechanisms based on periodic scanning of the entire set of pieces.

    Particular implementations of this approach are presented below.

    Vert.X Periodic Timer

    Within the Vert.X features #_executing_periodic_and_delayed_actions one can implement a mechanism that periodically retries the pieces and checks the status of the poline, changing it if necessary. There is a need to develop a mechanism that monitors pieces status in cluster mode, when each mod-orders / mod-orders-storage instance will start the scheduler entity. Thus, it is necessary to provide a solution so that the instances of the scheduler from each mod-orders / mod-orders-storage do not compete and do extra pieces checking.

    Separate Scheduler Application

    Since this will be a separate application it will solve the problem of multiple instance of scheduler noted in the previous option.

    PostgreSQL cron-job

    Task scheduler can be installed as PostgreSQL DB extension that executes scheduled tasks directly from the database, for example, pg_cron. This will allow to run poline status verification task following the algorithm from Figure 1 and implemented as a sequence of PostgreSQL commands.


  2. Interceptor-style mechanism

    This group of mechanisms is based on the injection of logic into the process, which checks the status of poline and its associated pieces. This logic checks the consistency of statuses and provides poline status changes, if necessary. The algorithm looks as shown on Figure 2.

    Figure 2 - A general algorithm of mechanisms based on consistency checking as part of retrieving flow.

    Checking and updating the PO line status upon retrieving

    PostgreSQL Trigger Functions

    A similar scenario can be made using the trigger function https://www.postgresql.org/docs/9.2/plpgsql-trigger.html that will be called for each state changing of pieces and make update the status of poline if necessary - poline data is updated when the underlying piece records are updated.

Solution Proposal