Code Monkey home page Code Monkey logo

Comments (3)

reset avatar reset commented on September 28, 2024

@cjimison yes, but it's not super clear how to do it because I've got a bit of work to do in naming and documentation. This is what you are looking for:

defmodule MyApp.Supervisor do
  def init([]) do
    children = [
      worker(Discovery.Poller, ["my_service", [
        {Discovery.Handler.NodeConnect, [
          {MyEventHandler, []}
        ]}
      ]], id: :my_service),
    ]

    supervise(children, strategy: :one_for_one)
  end
end

defmodule MyEventHandler do
  use Discovery.NodeConnector.Handler

  def on_connect(node, service, state), do: state
  def on_disconnect(node, service, state), do: state
end

The event handler will fire each time a connect / disconnect event is fired

from discovery.

cjimison avatar cjimison commented on September 28, 2024

Bad ass, this is exactly what I needed to know! I saw the NodeConnector.Handler in the code base, just wasn’t sure how add my own via the publicly exposed API (and I am now happily reverting my hacks :).

Thanks for the help!

-Chris

On Apr 8, 2015, at 11:16 AM, Jamie Winsor [email protected] wrote:

defmodule MyEventHandler do
use Discovery.NodeConnector.Handler

def on_connect(node, service, state), do: state
def on_disconnect(node, service, state), do: state
end

from discovery.

reset avatar reset commented on September 28, 2024

@cjimison no problem at all, this is something I need to make more clear in the documentation!

from discovery.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.