Master instance
===============

Service is needing to a master instance for correct work several mechanics. There are following processes:

    #) Move streams without any feedback to the status `handler_lost`. Any stream without feedback
       during `STREAM_STATUS_OBSOLETING_PERIOD` (20 seconds by default) will be move to status `handler_lost`.

    #) Restart stream after failure. If a stream has the status `failure` service will attempts to restart this stream.
       Attempt number is limited, each attempt is made after the specified time.

All running service instance choose the `master instance` for a correct execution these processes (without
race conditions and ect). Only master instance can execute this processes.

Choice of master
----------------

Every service try to get a database lock (update a field in the table `single_process_lock`).
If an instance got a lock it savea state `master` and  send heartbeat message to database further. Other instances
observe the heartbeat. If heartbeat is ended any service will try to be new master.


.. automodule:: luna_streams.app.streams_processes.master
	:members:
