Message from JavaScript discussions
February 2018
— No
My next project is creating a node.js little guy that reads from a mongodb, sets some redis keys deduced from mongo's data and then calls varnish for some cache cleanup. This will happen every (hour?) and it would be great if I could trigger this action by some api or shit
— Any idea on how structure my code properly?
— Start writing it first, then the problems with your code will be visible to you
— And then you can fix them from there
— Any advice on this trigger?
— Many ways
— If you trigger from API, you can just spin up HTTP from node
— Four hourly triggers, you can use cron / Task Scheduler in your system, OR you can keep node running and use npmjs.org/cron
— For the cron system I already choose for npmjs.org/cron
— Ahh, alright
— So basic structure:
mainProcedure() {
setSomeRedisKeys(getDataFromMongo())
cleanVarnishCache()
}
api.on('trigger', mainProcedure)
cron(mainProcedure)