@@ -49,16 +49,21 @@ instantiateDefinition = (d, role) ->
4949
5050 return def
5151
52+ defaultDiscoveryPeriod = 60
53+ defaultDiscoveryPeriod = parseInt process .env .MSGFLO_DISCOVERY_PERIOD if process .env .MSGFLO_DISCOVERY_PERIOD
54+
5255class Participant extends EventEmitter
5356 # @func gets called with inport, , and should return outport, outdata
54- constructor : (client , def , @func , role ) ->
57+ constructor : (client , def , @func , role , options = {} ) ->
5558 client = transport .getClient (client) if typeof client == ' string'
5659 @messaging = client
5760 role = ' unknown' if not role
5861 @definition = instantiateDefinition def, role
5962 @running = false
6063 newrelic = require ' ./newrelic'
6164 @_transactions = new newrelic.Transactions @definition
65+ @options = options
66+ @options .discoveryPeriod = defaultDiscoveryPeriod if not @options .discoveryPeriod # seconds
6267
6368 start : (callback ) ->
6469 @messaging .connect (err) =>
@@ -68,8 +73,14 @@ class Participant extends EventEmitter
6873 @setupPorts (err ) =>
6974 @running = true
7075 return callback err if err
71- @register (err ) ->
72- return callback err
76+ @register (err ) =>
77+ return callback err if err
78+ period = @options .discoveryPeriod * 1000 / 2.2 # try to send 2 messages before deadline
79+ setTimeout () =>
80+ @register (err ) ->
81+ console .log ' Could not send discovery message' , err if err
82+ , period
83+ return callback null
7384
7485 stop : (callback ) ->
7586 @running = false
0 commit comments