canonical / prometheus-juju-exporter

GNU General Public License v3.0
2 stars 8 forks source link

Implement graceful shutdown #8

Closed mkalcok closed 1 year ago

mkalcok commented 1 year ago

Currently there's no clean way to interrupt execution of the exporter. In addition, Unit Tests use rather ugly way of interrupting main loop in Exporter.trigger() by passing in special parameter to make sure the loop executes only once.

One of the ways to cleanly shutdown the process could be by handling KeyboardInterupt exception in Exporter.run(). Rough example:

def run():
    # prepare loop
    try:
        loop.run_unitl_complete(trigger_task)
    except KeyboardInterupt:
        # clean up resources, log last messages, etc ...
        exit(0)
    except Exception:
        exit(1)