the hook orm taking too long to load

空扰寡人 提交于 2019-11-27 20:31:57

I ran into this problem last night because of a slow internet connection between my laptop and the DB server. My solution was to create a new file in the config directory called orm.js (name doesn't really matter).

Then add the following code:

// config/orm.js
module.exports.orm = {
  _hookTimeout: 60000 // I used 60 seconds as my new timeout
};

I also found I had to change my pubsub timeout but that may not be necessary for you.

// config/pubsub.js
module.exports.pubsub = {
  _hookTimeout: 60000 // I used 60 seconds as my new timeout
};

Note: The other answer recommends changing the sails files inside the node_modules folder. This is almost always a bad idea because any npm update could revert your changes.

It is likely best to do this on a per env basis. Under config directory, you will have something like:

Then enter, inside module.exports of each:

module.exports = {

  hookTimeout: 40000

}

Notice, there is no need for an underscore in front of the attribute name either.

I realise this is quite an old question, but I also had the same problem. I was convinced it wasn't my connection.

My solution is to change your migration option for your models and you'll have a choice of 3

  1. safe - never auto-migrate my database(s). I will do it myself (by hand)
  2. alter - auto-migrate, but attempt to keep my existing data (experimental)
  3. drop - wipe/drop ALL my data and rebuild models every time I lift Sails

Got to config/models.js and in there put:

migrate: 'safe'

or whatever option from above you want to use.

There are two ways, which we can probably call them as:

1- System-wide method: (as @arcseldon has told)

Try to add the hookTimeout key to the project's config/env/development.js or config/env/production.js file. Next almost all the hooks (except some hooks, such as moduleloader) will retrieve the timeout value and consider it for themeselves.

2- Hook specific method: (as @davepreston has told)

create a [module-name].js file in the project's config folder and add _hookTimeout key to it. So, it will lead into assigning the timeout value only to that specific module. (Be careful about the specific json structure for the sails config files.)

Go to you node_modules folder and browse to \sails\lib\app\private

In your case you should go to this folder: C:\Users\KAMI\AppData\Roaming\npm\node_modules\sails\lib\app\private

Then open the file named loadHooks.js and go to the line that says:

var timeoutInterval = (sails.config[hooks[id].configKey || id] && sails.config[hooks[id].configKey || id]._hookTimeout) || sails.config.hookTimeout || 20000;

Change the last value in this line from 20000 to some higher value and save the file then run your application by "sails lift" as you normally do

NB: you may need to try out a few higher values instead of 20000 until you reach a value that works for you. My application successfully lifted when I changed the value to 50000

Go to models.js file and uncomment migrate: 'alter'

while running sails lift run this command in the command line sails lift hookTimeout=75000

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!