Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gaykey
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
Kio!
gaykey
Commits
5cf067c8
Commit
5cf067c8
authored
8 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
[Server] Refactor
parent
1d62a17c
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/index.ts
+27
-26
27 additions, 26 deletions
src/index.ts
with
27 additions
and
26 deletions
src/index.ts
+
27
−
26
View file @
5cf067c8
...
...
@@ -10,6 +10,7 @@ Error.stackTraceLimit = Infinity;
import
*
as
fs
from
'
fs
'
;
import
*
as
os
from
'
os
'
;
import
*
as
cluster
from
'
cluster
'
;
import
*
as
debug
from
'
debug
'
;
import
Logger
from
'
./utils/logger
'
;
import
*
as
chalk
from
'
chalk
'
;
import
portUsed
=
require
(
'
tcp-port-used
'
);
...
...
@@ -23,6 +24,8 @@ import DependencyInfo from './utils/dependencyInfo';
import
{
path
as
configPath
}
from
'
./config
'
;
import
loadConfig
from
'
./config
'
;
const
clusterLog
=
debug
(
'
misskey:cluster
'
);
// Init babel
require
(
'
babel-core/register
'
);
require
(
'
babel-polyfill
'
);
...
...
@@ -41,7 +44,7 @@ main();
/**
* Init proccess
*/
function
main
()
:
void
{
function
main
()
{
if
(
cluster
.
isMaster
)
{
masterMain
();
}
else
{
...
...
@@ -52,7 +55,7 @@ function main(): void {
/**
* Init master proccess
*/
async
function
masterMain
()
:
Promise
<
void
>
{
async
function
masterMain
()
{
let
initResult
:
InitResult
;
try
{
...
...
@@ -76,35 +79,15 @@ async function masterMain(): Promise<void> {
return
;
}
const
config
=
loadConfig
();
spawnWorkers
(()
=>
{
Logger
.
info
(
chalk
.
bold
.
green
(
`Now listening on port
${
config
.
port
}
`
));
// Listen new workers
cluster
.
on
(
'
fork
'
,
worker
=>
{
console
.
log
(
`Process forked: [
${
worker
.
id
}
]`
);
});
// Listen online workers
cluster
.
on
(
'
online
'
,
worker
=>
{
console
.
log
(
`Process is now online: [
${
worker
.
id
}
]`
);
});
// Listen for dying workers
cluster
.
on
(
'
exit
'
,
worker
=>
{
// Replace the dead worker,
// we're not sentimental
console
.
log
(
chalk
.
red
(
`[
${
worker
.
id
}
] died :(`
));
cluster
.
fork
();
});
Logger
.
info
(
chalk
.
bold
.
green
(
`Now listening on port
${
loadConfig
().
port
}
`
));
});
}
/**
* Init worker proccess
*/
function
workerMain
()
:
void
{
function
workerMain
()
{
// start server
require
(
'
./server
'
);
}
...
...
@@ -112,7 +95,7 @@ function workerMain(): void {
/**
* Init app
*/
async
function
init
()
:
Promise
<
InitResult
>
{
async
function
init
()
{
let
warn
=
false
;
Logger
.
info
(
'
Welcome to Misskey!
'
);
...
...
@@ -160,7 +143,7 @@ async function init(): Promise<InitResult> {
return
warn
?
InitResult
.
Warn
:
InitResult
.
Success
;
}
function
spawnWorkers
(
onComplete
:
any
)
:
void
{
function
spawnWorkers
(
onComplete
:
any
)
{
// Count the machine's CPUs
const
cpuCount
=
os
.
cpus
().
length
;
...
...
@@ -182,6 +165,24 @@ function spawnWorkers(onComplete: any): void {
});
}
// Listen new workers
cluster
.
on
(
'
fork
'
,
worker
=>
{
clusterLog
(
`Process forked: [
${
worker
.
id
}
]`
);
});
// Listen online workers
cluster
.
on
(
'
online
'
,
worker
=>
{
clusterLog
(
`Process is now online: [
${
worker
.
id
}
]`
);
});
// Listen for dying workers
cluster
.
on
(
'
exit
'
,
worker
=>
{
// Replace the dead worker,
// we're not sentimental
clusterLog
(
chalk
.
red
(
`[
${
worker
.
id
}
] died :(`
));
cluster
.
fork
();
});
// Display detail of unhandled promise rejection
process
.
on
(
'
unhandledRejection
'
,
console
.
dir
);
...
...
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