bodagetta
bodagetta

Reputation: 834

Sail.js requires server restart after running command to refresh database

From this question, Sails js using models outside web server I learned how to run a command from the terminal to update records. However, when I do this the changes don't show up until I restart the server. I'm using the sails-disk adapter and v0.9

Upvotes: 1

Views: 932

Answers (2)

bredikhin
bredikhin

Reputation: 9035

According to the source code, the application using sails-disk adapter loads the data from file only once, when the corresponding Waterline collection is being created. After that all the updates and destroys happen in the memory, then the data is being dumped to the file, but not being re-read.

That said, what's happening in your case is that once your server is running, it doesn't matter if you are changing the DB file (.tmp/disk.db) using your CLI instance, 'cause lifted Sails server won't know about the changes until it's restarted.

Long story short, the solution is simple: use another adapter. I would suggest you to check out sails-mongo or sails-redis (though the latter is still in development), for both Mongo and Redis have data auto expiry functionality (http://docs.mongodb.org/manual/tutorial/expire-data/, http://redis.io/commands/expire). Besides, sails-disk is not production-suitable anyways, so sooner or later you would need something else.

Upvotes: 2

JohnGalt
JohnGalt

Reputation: 2881

One way to accomplish deleting "expired records" over time is by rolling your own "cron-like job" in /config/bootstrap.js. In psuedo code it would look something like this:

module.exports.bootstrap = function (cb) {

  setInterval(function() {  < Insert Model Delete Code here>  }, 300000);

  cb();
};

The downside to this approach is if it throws it will stop the server. You might also take a look at kue.

Upvotes: 2

Related Questions