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

Ability to provide additional event emitter to emit on #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hgrubst
Copy link

@hgrubst hgrubst commented May 22, 2019

We call migrate on the startup of our application for each service that composes the application.
Whilst we can definitely use the migrate.emitter to log what is happening in our application, the fact that it is a shared instance on the migrate object makes it hard to log on the appropriate log category.
Here is a code example of the issue we face :

//service 1
log = getLogger('service1')
migrate.emitter.on('info', (data)=> log.debug(data))
migrate(...)

//service 2
log = getLogger('service2')
migrate.emitter.on('info', (data)=> log.debug(data))
//this is now registering a second listener to the same emitter which will end up logging stuff from service 1 as well
migrate(...)

I can think of other was to solve this, eg making migrate a class that you instanciate intead of shared instance so that each instance would have its own emitter.
Or you could also have a 'label' option passed in to migrate which could be used to emit more specifically :

//instead of 
internals.emitter.emit(name, data)
//do
internals.emitter.emit(`${name}-${options.label}`, data)

hgrubst added 2 commits May 22, 2019 11:41
…e one separete emitter per migrate if needed (for logging purposes for example)
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 97.079% when pulling 85191a7 on hgrubst:emitter-option into fae1f6d on vinicius0026:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants