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

added hot reload functionality #13

Merged
merged 1 commit into from May 22, 2018
Merged

added hot reload functionality #13

merged 1 commit into from May 22, 2018

Conversation

paulbakker
Copy link
Contributor

Currently importing restify/lib/chain. This will be fixed before releasing this as discussed in person with @hekike.

Copy link
Member

@hekike hekike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put some comments, feel free to keep them open for the experiment.

lib/install.js Outdated
try {
route = {
name: routeName,
method: method,
func: require(sourceFile)
func: process.env.HOT_RELOAD === 'true'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we turn this to an enroute option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean something in the opts object?
Can those be set from env vars so that we can enable it from tooling?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to pick up env vars from NQ and pass enroute options.
But for the experiment, it's okay to leave it like this.

lib/install.js Outdated
if(typeof process.env.HOT_RELOAD_BASEDIR !== 'undefined') {
//Delete code loaded from a specific base dir
Object.keys(require.cache).forEach(function (k) {
if(k.indexOf(process.env.HOT_RELOAD_BASEDIR) !== -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k.includes(process.env.HOT_RELOAD_BASEDIR) also k -> moduleName (or what it is)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k is the cache key. This is whatever require resolved to, which is usually a file path.
Rename to cacheKey maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

lib/install.js Outdated
@@ -6,6 +6,7 @@ var _ = require('lodash');
var assert = require('assert-plus');
var vasync = require('vasync');
var verror = require('verror');
var chainComposer = require('restify').helpers.chainComposer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just require('restify').helpers.compose

package.json Outdated
"restify-clients": "^1.4.0",
"uuid": "^2.0.3"
},
"dependencies": {
"ajv": "^4.8.0",
"assert-plus": "^1.0.0",
"lodash": "^4.16.4",
"restify": "^7.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^7.2.0

@paulbakker
Copy link
Contributor Author

@hekike Updated this PR to use bunyan for logging and clean up the code.

lib/install.js Outdated
@@ -32,6 +37,15 @@ function install(opts, cb) {
return cb1();
});

if (process.env.HOT_RELOAD) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DonutEspresso shouldn't this be an option and passing this ENV (property) in NQ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes +1 - let's make this a first class option and we can thread through the env var from a lower level.

lib/install.js Outdated
@@ -6,6 +6,11 @@ var _ = require('lodash');
var assert = require('assert-plus');
var vasync = require('vasync');
var verror = require('verror');
var compose = require('restify').helpers.compose;
var bunyan = require('bunyan');
var LOG = bunyan.createLogger({name: 'enroute'});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than create a new logger we should have enroute here create a child logger from an incoming logger - we'll make sure NQ threads it through:

var log = opts.log.child({ component: 'enroute' });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't that require another Restify release first, because today it doesn't pass a logger?

lib/install.js Outdated
@@ -32,6 +37,15 @@ function install(opts, cb) {
return cb1();
});

if (process.env.HOT_RELOAD) {
if (typeof process.env.HOT_RELOAD_BASEDIR !== 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are a multiple options for the hot reload option we should just make opts.hotReload a top level option.

"lodash": "^4.16.4",
"restify": "^7.2.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we use child loggers I don't think we'll need bunyan anymore. What's restify needed for? Or is that really a devDependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restify exports the new helpers.compose function to create a handler chain, which is used in the reloadProxy function.

renaming variable for readability

extra logging

Flatten handlers array

using composer function to build handler chain

now using a released version of restify

using bunyan for logging and cleaned up code

using log context for logs

hotReload is now an enroute option

Using child logger if set as option
@paulbakker
Copy link
Contributor Author

@DonutEspresso Now using child logger if a logger was passed in options and hotReload is option as well.

@DonutEspresso DonutEspresso requested a review from yunong May 22, 2018 01:57
@DonutEspresso DonutEspresso changed the base branch from master to hot-reload May 22, 2018 01:59
@DonutEspresso
Copy link
Member

Thanks @paulbakker ! I'm going to merge this into an origin branch and carry it through the finish line - appreciate the help!

@DonutEspresso DonutEspresso merged commit 390a6ba into restify:hot-reload May 22, 2018
@@ -32,6 +41,15 @@ function install(opts, cb) {
return cb1();
});

if (opts.enroute.hotReload) {
if (typeof opts.basePath !== 'undefined') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulbakker one qq - in what cases was basePath not defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an assumption that it’s possibly not defined. If this option is always required we can go without the check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool thanks! It's always required, so I think we can simply the check. 👍

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.

None yet

3 participants