Skip to content

Commit

Permalink
add job to restart app every morning to compact nedb
Browse files Browse the repository at this point in the history
  • Loading branch information
akralj committed Mar 19, 2018
1 parent 8974807 commit 08ea215
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
12 changes: 12 additions & 0 deletions client/src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ exports.default =
<style src='vuetify/dist/vuetify.min.css'></style>
<style lang="stylus">
//@import './stylus/main'
// print styles. use .no-print class on elements you dont want to show
@media print
@page
margin: 1em
body
overflow: auto
height: auto
.application--wrap .navigation-drawer, nav.toolbar, .no-print
display:none
main.content
padding: 0 !important
</style>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"lodash": "^4.17.5",
"mongodb": "^3.0.3",
"nedb": "^1.8.0",
"node-schedule": "^1.3.0",
"uuid": "^3.2.1",
"winston": "^2.4.0"
},
Expand Down
6 changes: 6 additions & 0 deletions server/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ promisedApp = new Promise (resolve) ->
app.use(express.urlencoded(extended: true))
app.configure(socketio())
app.configure(express.rest())

# add all endpoints
app.configure(require("./services/config"))
app.configure(require("./services/logs"))
app.configure(require("./services/data"))
app.configure(require("./services/method"))

# add jobs to app
app.configure(require('./jobs/'))

app.configure(middleware)

resolve app
Expand Down
11 changes: 9 additions & 2 deletions server/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
#
#

require("./app").then (app) ->
schedule = require('node-schedule')

require("./app").then (app) ->
port = app.serverConfig.appPort
server = app.listen(port)

server.on 'listening', ->
console.log("Feathers service running on port: #{port}")
app.logger.info("Feathers service running on 127.0.0.1:#{port}")

# kill app every morning to compact nedb
schedule.scheduleJob { hour: 5, minute: 55 }, () ->
app.logger.info("Killed app to compact nedb")
process.exit()
21 changes: 21 additions & 0 deletions server/jobs/getData.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
#
#

_ = require("lodash")
axios = require("axios")
fs = require("fs")
promisify = require("util").promisify
writeFile = promisify(require("fs").writeFile)


getData = (args) ->
{ app } = args

# do some async work (add your own code here)
result = await axios.get("http://localhost:#{app.serverConfig.appPort}/api/config")

return { message: "successful job", numberOfRecords: result.data.data.length }


module.exports = getData
6 changes: 4 additions & 2 deletions server/jobs/index.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#
#
#

Expand All @@ -7,14 +7,16 @@ createUuid = -> require('uuid').v4().replace(/\-/ig, '')

module.exports = ->
app = this
logs = app.service("/api/logs")
getData = require("./getData")

# 1. get all people
schedule.scheduleJob { hour: 22, minute: 0 }, () ->
result = await getData({ app: app })
console.log "did important work", result


result = await getData({ app: app })
console.log "did important work", result
###
# add this if you want logs under /api/logs
#logs = app.service("/api/logs")
Expand Down

0 comments on commit 08ea215

Please sign in to comment.