Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
04193dbc
Commit
04193dbc
authored
Sep 04, 2019
by
Nick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: database connection retries on start
parent
33e31a99
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
0 deletions
+19
-0
db.js
server/core/db.js
+19
-0
No files found.
server/core/db.js
View file @
04193dbc
...
...
@@ -108,6 +108,7 @@ module.exports = {
const
models
=
autoload
(
path
.
join
(
WIKI
.
SERVERPATH
,
'models'
))
// Set init tasks
let
conAttempts
=
0
let
initTasks
=
{
// -> Migrate DB Schemas
async
syncSchemas
()
{
...
...
@@ -115,10 +116,28 @@ module.exports = {
tableName
:
'migrations'
,
migrationSource
})
},
// -> Attempt initial connection
async
connect
()
{
try
{
WIKI
.
logger
.
info
(
'Connecting to database...'
)
await
self
.
knex
.
raw
(
'SELECT 1 + 1;'
)
WIKI
.
logger
.
info
(
'Database Connection Successful [ OK ]'
)
}
catch
(
err
)
{
if
(
conAttempts
<
10
)
{
WIKI
.
logger
.
error
(
`Database Connection Error:
${
err
.
code
}
${
err
.
address
}
:
${
err
.
port
}
`
)
WIKI
.
logger
.
warn
(
`Will retry in 3 seconds... [Attempt
${
++
conAttempts
}
of 10]`
)
await
new
Promise
(
resolve
=>
setTimeout
(
resolve
,
3000
))
await
initTasks
.
connect
()
}
else
{
throw
err
}
}
}
}
let
initTasksQueue
=
(
WIKI
.
IS_MASTER
)
?
[
initTasks
.
connect
,
initTasks
.
syncSchemas
]
:
[
()
=>
{
return
Promise
.
resolve
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment