move all bootstrap in initialization module
This commit is contained in:
@@ -38,8 +38,6 @@ const setupController = {
|
||||
config.status = 'DBCONF'
|
||||
config.db.logging = false
|
||||
|
||||
const settingsController = require('./settings')
|
||||
await settingsController.load()
|
||||
},
|
||||
|
||||
async setupDb (req, res) {
|
||||
|
||||
@@ -37,6 +37,4 @@ let config = {
|
||||
}
|
||||
}
|
||||
|
||||
config.load()
|
||||
|
||||
module.exports = config
|
||||
@@ -72,7 +72,6 @@ module.exports = {
|
||||
|
||||
async initSettings (req, res, next) {
|
||||
// initialize settings
|
||||
const settings = settingsController.settings
|
||||
res.locals.settings = cloneDeep(settingsController.settings)
|
||||
|
||||
if (res.locals.settings.smtp && res.locals.settings.smtp.auth) {
|
||||
|
||||
@@ -1,17 +1,40 @@
|
||||
const config = require('../server/config')
|
||||
const settingsController = require('./api/controller/settings')
|
||||
const log = require('../server/log')
|
||||
const db = require('./api/models/index')
|
||||
const dayjs = require('dayjs')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
||||
export default async function () {
|
||||
// export default async function () {
|
||||
module.exports = async function () {
|
||||
async function start (nuxt) {
|
||||
const log = require('../server/log')
|
||||
const config = require('../server/config')
|
||||
const settingsController = require('./api/controller/settings')
|
||||
const dayjs = require('dayjs')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
config.load()
|
||||
|
||||
if (config.status == 'READY') {
|
||||
await db.initialize()
|
||||
} else {
|
||||
if (process.env.GANCIO_DB_DIALECT) {
|
||||
const setupController = require('./api/controller/setup')
|
||||
const dbConf = {
|
||||
dialect: process.env.GANCIO_DB_DIALECT,
|
||||
storage: process.env.GANCIO_DB_STORAGE,
|
||||
host: process.env.GANCIO_DB_HOST,
|
||||
database: process.env.GANCIO_DB_DATABASE,
|
||||
username: process.env.GANCIO_DB_USERNAME,
|
||||
password: process.env.GANCIO_DB_PASSWORD,
|
||||
}
|
||||
|
||||
setupController._setupDb(dbConf)
|
||||
.catch(e => { process.exit(1) })
|
||||
}
|
||||
await settingsController.load()
|
||||
}
|
||||
|
||||
dayjs.extend(timezone)
|
||||
await settingsController.load()
|
||||
dayjs.tz.setDefault(settingsController.settings.instance_timezone)
|
||||
|
||||
let TaskManager
|
||||
if (config.status === 'READY') {
|
||||
if (config.status === 'READY' && process.env.NODE_ENV == 'production') {
|
||||
TaskManager = require('../server/taskManager').TaskManager
|
||||
TaskManager.start()
|
||||
}
|
||||
@@ -31,5 +54,11 @@ export default async function () {
|
||||
process.on('SIGTERM', shutdown)
|
||||
process.on('SIGINT', shutdown)
|
||||
}
|
||||
this.nuxt.hook('listen', start)
|
||||
|
||||
if (this.nuxt) {
|
||||
this.nuxt.hook('build:done', process.exit)
|
||||
return start(this.nuxt)
|
||||
} else {
|
||||
return start()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,30 +4,8 @@ const cookieParser = require('cookie-parser')
|
||||
// const metricsController = require('./metrics')
|
||||
// const promBundle = require('express-prom-bundle')
|
||||
// const metricsMiddleware = promBundle({ includeMethod: true })
|
||||
|
||||
const config = require('./config')
|
||||
|
||||
if (config.status == 'READY') {
|
||||
const db = require('./api/models/index')
|
||||
db.initialize()
|
||||
} else {
|
||||
if (process.env.GANCIO_DB_DIALECT) {
|
||||
const setupController = require('./api/controller/setup')
|
||||
const dbConf = {
|
||||
dialect: process.env.GANCIO_DB_DIALECT,
|
||||
storage: process.env.GANCIO_DB_STORAGE,
|
||||
host: process.env.GANCIO_DB_HOST,
|
||||
database: process.env.GANCIO_DB_DATABASE,
|
||||
username: process.env.GANCIO_DB_USERNAME,
|
||||
password: process.env.GANCIO_DB_PASSWORD,
|
||||
}
|
||||
|
||||
setupController._setupDb(dbConf)
|
||||
.catch(e => { process.exit(1) })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const helpers = require('./helpers')
|
||||
const log = require('./log')
|
||||
const api = require('./api')
|
||||
|
||||
@@ -54,6 +54,32 @@ class TaskManager {
|
||||
}
|
||||
|
||||
start (interval = loopInterval) {
|
||||
|
||||
// create and clean recurrent events
|
||||
this.add(new Task({
|
||||
name: 'CREATE_RECURRENT_EVENT',
|
||||
method: eventController._createRecurrent,
|
||||
repeatDelay: hour / 2, // check each half an hour
|
||||
repeat: true
|
||||
}))
|
||||
|
||||
// remove unrelated places
|
||||
this.add(new Task({
|
||||
name: 'CLEAN_UNUSED_PLACES',
|
||||
method: placeHelpers._cleanUnused,
|
||||
repeatDelay: day,
|
||||
repeat: true,
|
||||
callAtStart: true
|
||||
}))
|
||||
|
||||
this.add(new Task({
|
||||
name: 'CLEAN_UNUSED_TAGS',
|
||||
method: tagHelpers._cleanUnused,
|
||||
repeatDelay: day,
|
||||
repeat: true,
|
||||
callAtStart: true
|
||||
}))
|
||||
|
||||
log.info(`START TASK MANAGER WITH LOOP INTERVAL OF ${interval} seconds`)
|
||||
this.interval = interval
|
||||
this.timeout = setTimeout(this.tick.bind(this), interval * 1000)
|
||||
@@ -92,32 +118,6 @@ class TaskManager {
|
||||
}
|
||||
}
|
||||
|
||||
const TS = new TaskManager()
|
||||
|
||||
// create and clean recurrent events
|
||||
TS.add(new Task({
|
||||
name: 'CREATE_RECURRENT_EVENT',
|
||||
method: eventController._createRecurrent,
|
||||
repeatDelay: hour / 2, // check each half an hour
|
||||
repeat: true
|
||||
}))
|
||||
|
||||
// remove unrelated places
|
||||
TS.add(new Task({
|
||||
name: 'CLEAN_UNUSED_PLACES',
|
||||
method: placeHelpers._cleanUnused,
|
||||
repeatDelay: day,
|
||||
repeat: true,
|
||||
callAtStart: true
|
||||
}))
|
||||
|
||||
TS.add(new Task({
|
||||
name: 'CLEAN_UNUSED_TAGS',
|
||||
method: tagHelpers._cleanUnused,
|
||||
repeatDelay: day,
|
||||
repeat: true,
|
||||
callAtStart: true
|
||||
}))
|
||||
|
||||
// daily morning notification
|
||||
// TS.add(new Task({
|
||||
@@ -146,4 +146,4 @@ TS.add(new Task({
|
||||
// TS.add(new Task({ name: 'non removable #2', method: daje, args: ['non removable #2'] }))
|
||||
// TS.add(new Task({ name: 'non removable and repeat each #2', method: daje, args: ['nn rm and rpt #5'], repeatEach: 5 }))
|
||||
|
||||
module.exports = { Task, TaskManager: TS }
|
||||
module.exports = { Task, TaskManager: new TaskManager() }
|
||||
|
||||
Reference in New Issue
Block a user