Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code qualtiy control previously updated - added test directory to check. #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = mesh
var DEFAULT_HOST = (module.exports.DEFAULT_HOST = '127.0.0.1')
var DEFAULT_PORT = (module.exports.DEFAULT_PORT = 39999)

var intern = module.exports.intern = make_intern()
var intern = (module.exports.intern = make_intern())

var optioner = Optioner({
pin: Joi.alternatives().try(Joi.string(), Joi.object()),
Expand Down Expand Up @@ -159,11 +159,13 @@ function mesh(options) {
sneeze_opts.tag = void 0 !== sneeze_opts.tag
? sneeze_opts.tag
: void 0 !== tag
? null === tag ? null : 'seneca~' + tag
: 'seneca~mesh'
? null === tag ? null : 'seneca~' + tag
: 'seneca~mesh'

seneca.add('role:transport,cmd:listen',
intern.make_transport_listen(options, join, listen, init_done))
seneca.add(
'role:transport,cmd:listen',
intern.make_transport_listen(options, join, listen, init_done)
)

// call seneca.listen as a convenience
// subsequent seneca.listen calls will still publish to network
Expand Down Expand Up @@ -191,10 +193,9 @@ function mesh(options) {
})
}


function join(instance, raw_config, done) {
var client_instance = instance.root.delegate()
var config = seneca.util.clean(raw_config || {}, {proto:false})
var config = seneca.util.clean(raw_config || {}, { proto: false })

if (!config.pin && !config.pins) {
config.pin = 'null:true'
Expand Down Expand Up @@ -248,7 +249,6 @@ function mesh(options) {
})
})


sneeze.join(meta)

function add_client(meta) {
Expand All @@ -271,9 +271,8 @@ function mesh(options) {
)

var has_balance_client = !!balance_map[pin_config.pin]
var target_map = (balance_map[pin_config.pin] = balance_map[
pin_config.pin
] || {})
var target_map = (balance_map[pin_config.pin] =
balance_map[pin_config.pin] || {})

// this is a duplicate, so ignore
if (target_map[pin_config.id]) {
Expand All @@ -290,7 +289,6 @@ function mesh(options) {

target_map[pin_config.id] = true


if (!has_balance_client) {
// no balancer for this pin, so add one
client_instance.client({
Expand All @@ -313,7 +311,7 @@ function mesh(options) {
if (client_instance.id === meta.instance) {
return
}

var config = meta.config || {}
var pins = intern.resolve_pins(client_instance, config)

Expand All @@ -332,7 +330,8 @@ function mesh(options) {
}

client_instance.act('role:transport,type:balance,remove:client', {
config: pin_config, meta:meta
config: pin_config,
meta: meta
})
})
}
Expand All @@ -342,10 +341,9 @@ function mesh(options) {
})
}


function make_intern() {
return {
make_transport_listen: function (options, join, listen, init_done) {
make_transport_listen: function(options, join, listen, init_done) {
var listen_count = 0
var last_mesh_listen_err = null

Expand All @@ -370,9 +368,9 @@ function make_intern() {

// only finish mesh plugin init if all auto listens attempted
if (listen.length === listen_count) {
setTimeout(function(){
setTimeout(function() {
init_done(last_mesh_listen_err)
},options.jointime)
}, options.jointime)
}
})
} else {
Expand Down Expand Up @@ -443,9 +441,8 @@ function make_intern() {

addbase_funcmap: {
defined: function(seneca, options, bases, next) {
var add = (options.sneeze || {}).bases ||
options.bases ||
options.remotes || []
var add =
(options.sneeze || {}).bases || options.bases || options.remotes || []

add = add.filter(function(base) {
return base && 0 < base.length
Expand Down Expand Up @@ -522,7 +519,7 @@ function make_intern() {
var first = true

var base_addr =
(options.host || DEFAULT_HOST) + ':' + (options.port || DEFAULT_PORT)
(options.host || DEFAULT_HOST) + ':' + (options.port || DEFAULT_PORT)

if (options.isbase) {
var ri = options.discover.registry.refresh_interval
Expand Down Expand Up @@ -551,16 +548,16 @@ function make_intern() {

if (options.isbase) {
var prune_first =
Math.random() <
options.discover.registry.prune_first_probability
Math.random() <
options.discover.registry.prune_first_probability

if (prune_first || -1 === add.indexOf(base_addr)) {
add.push(base_addr)
add = _.uniq(add)

if (
prune_first &&
options.discover.registry.prune_bound < add.length
options.discover.registry.prune_bound < add.length
) {
add.shift()
}
Expand Down
Loading