qwan / fm-orchestrator

Forked from fm-orchestrator 6 years ago
Clone

d622efc Replace further work by Scheduler class based on the "sched" module.

15 files Authored by jkaluza 4 years ago, Committed by qwan 4 years ago,
    Replace further work by Scheduler class based on the "sched" module.
    
    To support multiple backend, we need to get rid of `further_work` concept
    which is used in multiple places in the MBS code. Before this commit, if
    one handler wanted to execute another handler, it planned this work by
    constructing fake message and returning it. MBSConsumer then planned
    its execution by adding it into the event loop.
    
    In this commit, the new `events.scheduler` instance of new Scheduler
    class is used to acomplish this. If handler wants to execute another
    handler, it simply schedules it using `events.scheduler.add` method.
    
    In the end of each handler, the `events.scheduler.run` method is
    executed which calls all the scheduled handlers.
    
    The idea is that when Celery is enabled, we can change the
    `Scheduler.run` method to execute the handlers using the Celery, while
    during the local builds, we could execute them directly without Celery.
    
    Use of Scheduler also fixes the issue with ordering of such calls. If
    we would call the handlers directly, they could have been executed
    in the middle of another handler leading to behavior incompatible
    with the current `further_work` concept. Using the Scheduler, these
    calls are executed always in the end of the handler no matter when
    they have been scheduled.
    
        
file modified
+27 -58
file modified
+27 -38
file modified
+46 -46