Q: I have two applications that are connected to each other. When I remove the relationship, the order in which both applications terminate the relationship is very important. The client side needs to terminate the relationship before the server side, else, the client will try to connect to a nonexistent server and fail. How Can I do that?
A: This is where the
<relation>-broken flags come in. The
relation-departed flag will be set immediately after the removal of the relationship is requested. This flag should be used to trigger a termination from the client side. Only when every related unit has handled the
relation-departed flag, the
relation-broken flag will be called. This means that the server side of the relationship knows that every client has disconnected when the
relation-broken flag is set.
@when('server.relation-departed') def handle_server_departed(server_relation): stop_client(server_relation)
@when('client.relation-broken') def handle_client_broken(client_relation): stop_server(client_relation)
# Clients requesting the docker container should be notified before we remove the container. # This is so that clients don't try to connect to removed containers. That is the reason why # We react to the `relation-broken` hook and not the `relation-departed` hook to give Clients # time to disconnect. `relation-broken` will only be called after every related unit has # handled the `relation-departed` hook.