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
a1031275
Unverified
Commit
a1031275
authored
Apr 12, 2021
by
LK HO
Committed by
GitHub
Apr 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: graceful shutdown (#3821)
* fix: missing graceful shutdown handler * fix: asar - use async fs operation * fix: scheduler - graceful shutdown and wait for running jobs to complete
parent
71aa0c93
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
23 deletions
+39
-23
asar.js
server/core/asar.js
+4
-4
kernel.js
server/core/kernel.js
+10
-8
scheduler.js
server/core/scheduler.js
+12
-11
index.js
server/index.js
+13
-0
No files found.
server/core/asar.js
View file @
a1031275
...
...
@@ -40,11 +40,11 @@ module.exports = {
}
},
async
unload
()
{
if
(
this
.
fdCache
)
{
const
fds
=
Object
.
values
(
this
.
fdCache
)
if
(
fds
.
length
>
0
)
{
WIKI
.
logger
.
info
(
'Closing ASAR file descriptors...'
)
for
(
const
fdItem
in
this
.
fdCache
)
{
fs
.
closeSync
(
this
.
fdCache
[
fdItem
].
fd
)
}
const
closeAsync
=
require
(
'util'
).
promisify
(
fs
.
close
)
await
Promise
.
all
(
fds
.
map
(
x
=>
closeAsync
(
x
.
fd
)))
this
.
fdCache
=
{}
}
},
...
...
server/core/kernel.js
View file @
a1031275
...
...
@@ -107,19 +107,21 @@ module.exports = {
* Graceful shutdown
*/
async
shutdown
()
{
if
(
WIKI
.
models
)
{
await
WIKI
.
models
.
unsubscribeToNotifications
()
await
WIKI
.
models
.
knex
.
client
.
pool
.
destroy
()
await
WIKI
.
models
.
knex
.
destroy
()
if
(
WIKI
.
servers
)
{
await
WIKI
.
servers
.
stopServers
()
}
if
(
WIKI
.
scheduler
)
{
WIKI
.
scheduler
.
stop
()
await
WIKI
.
scheduler
.
stop
()
}
if
(
WIKI
.
models
)
{
await
WIKI
.
models
.
unsubscribeToNotifications
()
if
(
WIKI
.
models
.
knex
)
{
await
WIKI
.
models
.
knex
.
destroy
()
}
}
if
(
WIKI
.
asar
)
{
await
WIKI
.
asar
.
unload
()
}
if
(
WIKI
.
servers
)
{
await
WIKI
.
servers
.
stopServers
()
}
process
.
exit
(
0
)
}
}
server/core/scheduler.js
View file @
a1031275
...
...
@@ -12,7 +12,8 @@ class Job {
schedule
=
'P1D'
,
repeat
=
false
,
worker
=
false
})
{
},
queue
)
{
this
.
queue
=
queue
this
.
finished
=
Promise
.
resolve
()
this
.
name
=
name
this
.
immediate
=
immediate
...
...
@@ -27,6 +28,7 @@ class Job {
* @param {Object} data Job Data
*/
start
(
data
)
{
this
.
queue
.
jobs
.
push
(
this
)
if
(
this
.
immediate
)
{
this
.
invoke
(
data
)
}
else
{
...
...
@@ -82,16 +84,20 @@ class Job {
}
catch
(
err
)
{
WIKI
.
logger
.
warn
(
err
)
}
if
(
this
.
repeat
)
{
if
(
this
.
repeat
&&
this
.
queue
.
jobs
.
includes
(
this
)
)
{
this
.
queue
(
data
)
}
else
{
this
.
stop
().
catch
(()
=>
{})
}
}
/**
* Stop any future job invocation from occuring
*/
stop
()
{
async
stop
()
{
clearTimeout
(
this
.
timeout
)
this
.
queue
.
jobs
=
this
.
queue
.
jobs
.
filter
(
x
=>
x
!==
this
)
return
this
.
finished
}
}
...
...
@@ -118,16 +124,11 @@ module.exports = {
})
},
registerJob
(
opts
,
data
)
{
const
job
=
new
Job
(
opts
)
const
job
=
new
Job
(
opts
,
this
)
job
.
start
(
data
)
if
(
job
.
repeat
)
{
this
.
jobs
.
push
(
job
)
}
return
job
},
stop
()
{
this
.
jobs
.
forEach
(
job
=>
{
job
.
stop
()
})
async
stop
()
{
return
Promise
.
all
(
this
.
jobs
.
map
(
job
=>
job
.
stop
()))
}
}
server/index.js
View file @
a1031275
...
...
@@ -33,3 +33,16 @@ WIKI.logger = require('./core/logger').init('MASTER')
// ----------------------------------------
WIKI
.
kernel
.
init
()
// ----------------------------------------
// Register exit handler
// ----------------------------------------
process
.
on
(
'SIGINT'
,
()
=>
{
WIKI
.
kernel
.
shutdown
()
})
process
.
on
(
'message'
,
(
msg
)
=>
{
if
(
msg
===
'shutdown'
)
{
WIKI
.
kernel
.
shutdown
()
}
})
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