Prevent job queue to be started before plugins
This commit is contained in:
parent
fc3784583c
commit
4404a7c467
|
@ -44,7 +44,7 @@ async function run () {
|
||||||
filePath: resolve(options.import)
|
filePath: resolve(options.import)
|
||||||
}
|
}
|
||||||
|
|
||||||
JobQueue.Instance.init(true)
|
JobQueue.Instance.init()
|
||||||
await JobQueue.Instance.createJob({ type: 'video-file-import', payload: dataInput })
|
await JobQueue.Instance.createJob({ type: 'video-file-import', payload: dataInput })
|
||||||
console.log('Import job for video %s created.', video.uuid)
|
console.log('Import job for video %s created.', video.uuid)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ run()
|
||||||
async function run () {
|
async function run () {
|
||||||
await initDatabaseModels(true)
|
await initDatabaseModels(true)
|
||||||
|
|
||||||
JobQueue.Instance.init(true)
|
JobQueue.Instance.init()
|
||||||
|
|
||||||
let ids: number[] = []
|
let ids: number[] = []
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ async function run () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JobQueue.Instance.init(true)
|
JobQueue.Instance.init()
|
||||||
|
|
||||||
video.state = VideoState.TO_TRANSCODE
|
video.state = VideoState.TO_TRANSCODE
|
||||||
await video.save()
|
await video.save()
|
||||||
|
|
|
@ -21,7 +21,7 @@ async function run () {
|
||||||
|
|
||||||
await initDatabaseModels(true)
|
await initDatabaseModels(true)
|
||||||
|
|
||||||
JobQueue.Instance.init(true)
|
JobQueue.Instance.init()
|
||||||
|
|
||||||
const ids = await VideoModel.listLocalIds()
|
const ids = await VideoModel.listLocalIds()
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ async function run () {
|
||||||
console.log('Generate avatar miniatures from existing avatars.')
|
console.log('Generate avatar miniatures from existing avatars.')
|
||||||
|
|
||||||
await initDatabaseModels(true)
|
await initDatabaseModels(true)
|
||||||
JobQueue.Instance.init(true)
|
JobQueue.Instance.init()
|
||||||
|
|
||||||
const accounts: AccountModel[] = await AccountModel.findAll({
|
const accounts: AccountModel[] = await AccountModel.findAll({
|
||||||
include: [
|
include: [
|
||||||
|
|
|
@ -351,6 +351,12 @@ async function startApplication () {
|
||||||
ApplicationModel.updateNodeVersions()
|
ApplicationModel.updateNodeVersions()
|
||||||
.catch(err => logger.error('Cannot update node versions.', { err }))
|
.catch(err => logger.error('Cannot update node versions.', { err }))
|
||||||
|
|
||||||
|
JobQueue.Instance.start()
|
||||||
|
.catch(err => {
|
||||||
|
logger.error('Cannot start job queue.', { err })
|
||||||
|
process.exit(-1)
|
||||||
|
})
|
||||||
|
|
||||||
logger.info('HTTP server listening on %s:%d', hostname, port)
|
logger.info('HTTP server listening on %s:%d', hostname, port)
|
||||||
logger.info('Web server: %s', WEBSERVER.URL)
|
logger.info('Web server: %s', WEBSERVER.URL)
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ class JobQueue {
|
||||||
private constructor () {
|
private constructor () {
|
||||||
}
|
}
|
||||||
|
|
||||||
init (produceOnly = false) {
|
init () {
|
||||||
// Already initialized
|
// Already initialized
|
||||||
if (this.initialized === true) return
|
if (this.initialized === true) return
|
||||||
this.initialized = true
|
this.initialized = true
|
||||||
|
@ -176,10 +176,10 @@ class JobQueue {
|
||||||
this.jobRedisPrefix = 'bull-' + WEBSERVER.HOST
|
this.jobRedisPrefix = 'bull-' + WEBSERVER.HOST
|
||||||
|
|
||||||
for (const handlerName of (Object.keys(handlers) as JobType[])) {
|
for (const handlerName of (Object.keys(handlers) as JobType[])) {
|
||||||
this.buildWorker(handlerName, produceOnly)
|
this.buildWorker(handlerName)
|
||||||
this.buildQueue(handlerName)
|
this.buildQueue(handlerName)
|
||||||
this.buildQueueScheduler(handlerName, produceOnly)
|
this.buildQueueScheduler(handlerName)
|
||||||
this.buildQueueEvent(handlerName, produceOnly)
|
this.buildQueueEvent(handlerName)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.flowProducer = new FlowProducer({
|
this.flowProducer = new FlowProducer({
|
||||||
|
@ -191,9 +191,9 @@ class JobQueue {
|
||||||
this.addRepeatableJobs()
|
this.addRepeatableJobs()
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildWorker (handlerName: JobType, produceOnly: boolean) {
|
private buildWorker (handlerName: JobType) {
|
||||||
const workerOptions: WorkerOptions = {
|
const workerOptions: WorkerOptions = {
|
||||||
autorun: !produceOnly,
|
autorun: false,
|
||||||
concurrency: this.getJobConcurrency(handlerName),
|
concurrency: this.getJobConcurrency(handlerName),
|
||||||
prefix: this.jobRedisPrefix,
|
prefix: this.jobRedisPrefix,
|
||||||
connection: this.getRedisConnection()
|
connection: this.getRedisConnection()
|
||||||
|
@ -246,9 +246,9 @@ class JobQueue {
|
||||||
this.queues[handlerName] = queue
|
this.queues[handlerName] = queue
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildQueueScheduler (handlerName: JobType, produceOnly: boolean) {
|
private buildQueueScheduler (handlerName: JobType) {
|
||||||
const queueSchedulerOptions: QueueSchedulerOptions = {
|
const queueSchedulerOptions: QueueSchedulerOptions = {
|
||||||
autorun: !produceOnly,
|
autorun: false,
|
||||||
connection: this.getRedisConnection(),
|
connection: this.getRedisConnection(),
|
||||||
prefix: this.jobRedisPrefix,
|
prefix: this.jobRedisPrefix,
|
||||||
maxStalledCount: 10
|
maxStalledCount: 10
|
||||||
|
@ -260,9 +260,9 @@ class JobQueue {
|
||||||
this.queueSchedulers[handlerName] = queueScheduler
|
this.queueSchedulers[handlerName] = queueScheduler
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildQueueEvent (handlerName: JobType, produceOnly: boolean) {
|
private buildQueueEvent (handlerName: JobType) {
|
||||||
const queueEventsOptions: QueueEventsOptions = {
|
const queueEventsOptions: QueueEventsOptions = {
|
||||||
autorun: !produceOnly,
|
autorun: false,
|
||||||
connection: this.getRedisConnection(),
|
connection: this.getRedisConnection(),
|
||||||
prefix: this.jobRedisPrefix
|
prefix: this.jobRedisPrefix
|
||||||
}
|
}
|
||||||
|
@ -304,6 +304,23 @@ class JobQueue {
|
||||||
return Promise.all(promises)
|
return Promise.all(promises)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start () {
|
||||||
|
const promises = Object.keys(this.workers)
|
||||||
|
.map(handlerName => {
|
||||||
|
const worker: Worker = this.workers[handlerName]
|
||||||
|
const queueScheduler: QueueScheduler = this.queueSchedulers[handlerName]
|
||||||
|
const queueEvent: QueueEvents = this.queueEvents[handlerName]
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
worker.run(),
|
||||||
|
queueScheduler.run(),
|
||||||
|
queueEvent.run()
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
return Promise.all(promises)
|
||||||
|
}
|
||||||
|
|
||||||
async pause () {
|
async pause () {
|
||||||
for (const handlerName of Object.keys(this.workers)) {
|
for (const handlerName of Object.keys(this.workers)) {
|
||||||
const worker: Worker = this.workers[handlerName]
|
const worker: Worker = this.workers[handlerName]
|
||||||
|
|
Loading…
Reference in New Issue