heimdall v0.6.8 Heimdall.Marathon.BingeWatch

There’s a Marathon playing, and we’re gonna BingeWatch it.

This module is for handling events streamed from Marathon. Given any event it will query all running apps, and rebuild the dynmaic routes based on the labels of each app.

This module implements the GenServer behavour, and begins streaming Marathon events to itself in start_link/0.

Summary

Functions

Builds a route given a map that represents the Marathon config for an app. The config must have a labels map, as well as a heimdall.host and heimdall.path in the labels map

Builds a list of routest given a list of map that represent the Marathon app configs. It will filter out all of the apps that do not have a proper Heimdall configuration set up (i.e. they don’t have a labels with heimdall.host and heimdall.path

handle_info/2 handles responses streamed in from Marathon

Reloads and register routes from Marathon

Converts a string to an elixir module atom. Will throw an argument error if the module does not exist. (There is no need to give a fully qualified erlang module name, just refer to it as you would in elixir)

Functions

build_route(app)

Builds a route given a map that represents the Marathon config for an app. The config must have a labels map, as well as a heimdall.host and heimdall.path in the labels map.

heimdall.filters and heimdall.opts are optional, they will default to an empty list and tuple respectively.

build_routes(apps)

Builds a list of routest given a list of map that represent the Marathon app configs. It will filter out all of the apps that do not have a proper Heimdall configuration set up (i.e. they don’t have a labels with heimdall.host and heimdall.path.

handle_info(msg, state)

handle_info/2 handles responses streamed in from Marathon

If a response from Marathon gives back anything other than 200, or if there is an error connecting, BingeWatch will attempt to reconnect with exponential back-off.

Any chunked response other than a carriage return (which is used as a keep-alive) from Marathon will trigger a reload of the routes config.

Also other message to handle_info/2 will be ignored.

register_routes(routes)
reload_marathon_routes(marathon_url)

Reloads and register routes from Marathon.

When called, it will make a HTTP request to Marathon to attempt to retrieve and decode the list of all running apps. It will use this list to build an internal representation of routes based on the config for each app, and register the routes with Heimdall.DynamicRoutes using Heimdall.DynamicRoutes.register/5

start_link(args)
string_to_module(module_string)

Converts a string to an elixir module atom. Will throw an argument error if the module does not exist. (There is no need to give a fully qualified erlang module name, just refer to it as you would in elixir)

Examples

iex>Heimdall.Marathon.BingeWatch.string_to_module("Heimdall.Marathon.BingeWatch")
Heimdall.Marathon.BingeWatch