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
011be49a
Unverified
Commit
011be49a
authored
Oct 02, 2022
by
Nicolas Giard
Committed by
GitHub
Oct 02, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: scheduler - simple tasks handling (#5703)
parent
f4ce5ff6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
4 deletions
+32
-4
scheduler.js
server/core/scheduler.js
+6
-2
3.0.0.js
server/db/migrations/3.0.0.js
+2
-2
check-version.js
server/tasks/simple/check-version.js
+12
-0
update-locales.js
server/tasks/simple/update-locales.js
+12
-0
purge-uploads.js
server/tasks/workers/purge-uploads.js
+0
-0
No files found.
server/core/scheduler.js
View file @
011be49a
const
{
DynamicThreadPool
}
=
require
(
'poolifier'
)
const
{
DynamicThreadPool
}
=
require
(
'poolifier'
)
const
os
=
require
(
'node:os'
)
const
os
=
require
(
'node:os'
)
const
{
setTimeout
}
=
require
(
'node:timers/promises'
)
const
{
setTimeout
}
=
require
(
'node:timers/promises'
)
const
autoload
=
require
(
'auto-load'
)
const
path
=
require
(
'node:path'
)
module
.
exports
=
{
module
.
exports
=
{
pool
:
null
,
pool
:
null
,
maxWorkers
:
1
,
maxWorkers
:
1
,
activeWorkers
:
0
,
activeWorkers
:
0
,
tasks
:
null
,
async
init
()
{
async
init
()
{
this
.
maxWorkers
=
WIKI
.
config
.
scheduler
.
workers
===
'auto'
?
os
.
cpus
().
length
:
WIKI
.
config
.
scheduler
.
workers
this
.
maxWorkers
=
WIKI
.
config
.
scheduler
.
workers
===
'auto'
?
os
.
cpus
().
length
:
WIKI
.
config
.
scheduler
.
workers
WIKI
.
logger
.
info
(
`Initializing Worker Pool (Limit:
${
this
.
maxWorkers
}
)...`
)
WIKI
.
logger
.
info
(
`Initializing Worker Pool (Limit:
${
this
.
maxWorkers
}
)...`
)
...
@@ -14,6 +17,7 @@ module.exports = {
...
@@ -14,6 +17,7 @@ module.exports = {
exitHandler
:
()
=>
WIKI
.
logger
.
debug
(
'A worker has gone offline.'
),
exitHandler
:
()
=>
WIKI
.
logger
.
debug
(
'A worker has gone offline.'
),
onlineHandler
:
()
=>
WIKI
.
logger
.
debug
(
'New worker is online.'
)
onlineHandler
:
()
=>
WIKI
.
logger
.
debug
(
'New worker is online.'
)
})
})
this
.
tasks
=
autoload
(
path
.
join
(
WIKI
.
SERVERPATH
,
'tasks/simple'
))
return
this
return
this
},
},
async
start
()
{
async
start
()
{
...
@@ -56,7 +60,7 @@ module.exports = {
...
@@ -56,7 +60,7 @@ module.exports = {
data
:
job
.
payload
data
:
job
.
payload
})
})
}
else
{
}
else
{
await
this
.
tasks
[
job
.
task
](
job
.
payload
)
}
}
}
}
})
})
...
@@ -66,7 +70,7 @@ module.exports = {
...
@@ -66,7 +70,7 @@ module.exports = {
},
},
async
stop
()
{
async
stop
()
{
WIKI
.
logger
.
info
(
'Stopping Scheduler...'
)
WIKI
.
logger
.
info
(
'Stopping Scheduler...'
)
await
this
.
pool
.
stop
()
await
this
.
pool
.
destroy
()
WIKI
.
logger
.
info
(
'Scheduler: [ STOPPED ]'
)
WIKI
.
logger
.
info
(
'Scheduler: [ STOPPED ]'
)
}
}
}
}
server/db/migrations/3.0.0.js
View file @
011be49a
...
@@ -669,12 +669,12 @@ exports.up = async knex => {
...
@@ -669,12 +669,12 @@ exports.up = async knex => {
await
knex
(
'jobSchedule'
).
insert
([
await
knex
(
'jobSchedule'
).
insert
([
{
{
task
:
'update
-l
ocales'
,
task
:
'update
L
ocales'
,
cron
:
'0 0 * * *'
,
cron
:
'0 0 * * *'
,
type
:
'system'
type
:
'system'
},
},
{
{
task
:
'check
-v
ersion'
,
task
:
'check
V
ersion'
,
cron
:
'0 0 * * *'
,
cron
:
'0 0 * * *'
,
type
:
'system'
type
:
'system'
}
}
...
...
server/tasks/simple/check-version.js
0 → 100644
View file @
011be49a
module
.
exports
=
async
(
payload
)
=>
{
WIKI
.
logger
.
info
(
'Checking for latest version...'
)
try
{
// TODO: Fetch latest version
WIKI
.
logger
.
info
(
'Checked for latest version: [ COMPLETED ]'
)
}
catch
(
err
)
{
WIKI
.
logger
.
error
(
'Checking for latest version: [ FAILED ]'
)
WIKI
.
logger
.
error
(
err
.
message
)
}
}
server/tasks/simple/update-locales.js
0 → 100644
View file @
011be49a
module
.
exports
=
async
(
payload
)
=>
{
WIKI
.
logger
.
info
(
'Fetching latest localization data...'
)
try
{
// TODO: Fetch locale updates
WIKI
.
logger
.
info
(
'Fetched latest localization data: [ COMPLETED ]'
)
}
catch
(
err
)
{
WIKI
.
logger
.
error
(
'Fetching latest localization data: [ FAILED ]'
)
WIKI
.
logger
.
error
(
err
.
message
)
}
}
server/tasks/
background
/purge-uploads.js
→
server/tasks/
workers
/purge-uploads.js
View file @
011be49a
File moved
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