Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
simcaq-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
simcaq
simcaq-node
Commits
a0da548f
There was a problem fetching the pipeline summary.
Commit
a0da548f
authored
7 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Add node cluster library
parent
a3c91fbb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!116
Release v1.0.0
,
!39
Cluster
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/server.js
+32
-18
32 additions, 18 deletions
src/server.js
with
32 additions
and
18 deletions
src/server.js
+
32
−
18
View file @
a0da548f
const
debug
=
require
(
'
debug
'
)(
'
node-express-base
'
);
const
debug
=
require
(
'
debug
'
)(
'
simcaq-api
'
);
const
libs
=
`
${
process
.
cwd
()}
/libs`
;
const
config
=
require
(
`
${
libs
}
/config`
);
const
log
=
require
(
`
${
libs
}
/log`
)(
module
);
const
app
=
require
(
`
${
libs
}
/app`
);
const
compatVersion
=
require
(
`
${
libs
}
/middlewares/checkVersion`
);
const
cluster
=
require
(
'
cluster
'
);
// Check if Node version is compatible
if
(
!
compatVersion
())
{
process
.
exit
(
1
);
}
// Set default port: first environment variable PORT, then configuration and last 3000
app
.
set
(
'
port
'
,
process
.
env
.
PORT
||
config
.
port
||
3000
);
process
.
env
.
NODE_ENV
=
process
.
env
.
NODE_ENV
||
'
development
'
;
// Set default ip: first environment variable IOP, then configuration and last '127.0.0.1'
app
.
set
(
'
ip
'
,
process
.
env
.
IP
||
config
.
ip
||
'
127.0.0.1
'
);
const
server
=
app
.
listen
(
app
.
get
(
'
port
'
),
()
=>
{
log
.
info
(
`Express server listening on port
${
server
.
address
().
port
}
`
);
});
// For testing
module
.
exports
=
server
;
if
(
cluster
.
isMaster
)
{
log
.
info
(
`Master
${
process
.
pid
}
is running`
);
const
numCPUs
=
require
(
'
os
'
).
cpus
().
length
;
for
(
let
i
=
0
;
i
<
numCPUs
;
++
i
)
{
cluster
.
fork
();
}
// Caso uma instâcia morra
cluster
.
on
(
'
exit
'
,
(
worker
,
code
,
signal
)
=>
{
log
.
info
(
`Worker
${
worker
.
process
.
pid
}
died`
);
// Revive a instância
cluster
.
fork
();
});
}
else
{
// Set default port: first environment variable PORT, then configuration and last 3000
app
.
set
(
'
port
'
,
process
.
env
.
PORT
||
config
.
port
||
3000
);
process
.
env
.
NODE_ENV
=
process
.
env
.
NODE_ENV
||
'
development
'
;
// Set default ip: first environment variable IOP, then configuration and last '127.0.0.1'
app
.
set
(
'
ip
'
,
process
.
env
.
IP
||
config
.
ip
||
'
127.0.0.1
'
);
const
server
=
app
.
listen
(
app
.
get
(
'
port
'
),
()
=>
{
log
.
info
(
`Express server listening on port
${
server
.
address
().
port
}
`
);
});
log
.
info
(
`Worker
${
cluster
.
worker
.
id
}
is running`
);
// For testing
module
.
exports
=
server
;
}
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