Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
6e347e42
Commit
6e347e42
authored
6 years ago
by
Aya Morisawa
Committed by
syuilo
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor checkMongoDb (#3339)
parent
28ccb141
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/index.ts
+20
-15
20 additions, 15 deletions
src/index.ts
with
20 additions
and
15 deletions
src/index.ts
+
20
−
15
View file @
6e347e42
...
...
@@ -23,6 +23,7 @@ import notesStats from './daemons/notes-stats';
import
loadConfig
from
'
./config/load
'
;
import
{
Config
}
from
'
./config/types
'
;
import
{
lessThan
}
from
'
./prelude/array
'
;
import
{
Db
}
from
'
mongodb
'
;
const
clusterLog
=
debug
(
'
misskey:cluster
'
);
const
ev
=
new
Xev
();
...
...
@@ -191,32 +192,36 @@ async function init(): Promise<Config> {
}
// Try to connect to MongoDB
checkMongoD
b
(
config
);
await
checkMongoD
B
(
config
);
return
config
;
}
function
checkMongoDb
(
config
:
Config
)
{
const
requiredMongoDBVersion
=
[
3
,
6
];
function
checkMongoDB
(
config
:
Config
):
Promise
<
void
>
{
const
mongoDBLogger
=
new
Logger
(
'
MongoDB
'
);
const
u
=
config
.
mongodb
.
user
?
encodeURIComponent
(
config
.
mongodb
.
user
)
:
null
;
const
p
=
config
.
mongodb
.
pass
?
encodeURIComponent
(
config
.
mongodb
.
pass
)
:
null
;
const
uri
=
`mongodb://
${
u
&&
p
?
`
${
u
}
:****@`
:
''
}${
config
.
mongodb
.
host
}
:
${
config
.
mongodb
.
port
}
/
${
config
.
mongodb
.
db
}
`
;
mongoDBLogger
.
info
(
`Connecting to
${
uri
}
`
);
mongo
.
then
(()
=>
{
nativeDbConn
().
then
(
db
=>
db
.
admin
().
serverInfo
()).
then
(
x
=>
x
.
version
).
then
((
version
:
string
)
=>
{
mongoDBLogger
.
info
(
`Version:
${
version
}
`
);
if
(
lessThan
(
version
.
split
(
'
.
'
).
map
(
x
=>
parseInt
(
x
,
10
)),
[
3
,
6
]))
{
mongoDBLogger
.
error
(
`MongoDB version is less than 3.6. Please upgrade it.`
);
process
.
exit
(
1
);
}
});
return
mongo
.
then
(
async
()
=>
{
mongoDBLogger
.
succ
(
'
Connectivity confirmed
'
);
})
.
catch
(
err
=>
{
mongoDBLogger
.
error
(
err
.
message
);
});
const
runningMongoDBVersion
=
(
await
nativeDbConn
().
then
(
getMongoDBVersion
)).
split
(
'
.
'
).
map
(
x
=>
parseInt
(
x
,
10
));
mongoDBLogger
.
info
(
`Version:
${
runningMongoDBVersion
.
join
(
'
.
'
)}
`
);
if
(
lessThan
(
runningMongoDBVersion
,
requiredMongoDBVersion
))
{
mongoDBLogger
.
error
(
`MongoDB version is less than
${
requiredMongoDBVersion
.
join
(
'
.
'
)}
. Please upgrade it.`
);
process
.
exit
(
1
);
}
}).
catch
(
err
=>
{
mongoDBLogger
.
error
(
err
.
message
);
});
}
async
function
getMongoDBVersion
(
db
:
Db
):
Promise
<
string
>
{
return
(
await
db
.
admin
().
serverInfo
()).
version
;
}
async
function
spawnWorkers
(
limit
:
number
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment