mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-06 00:16:02 +01:00
Update:JSDocs for task manager
This commit is contained in:
parent
5644a40a03
commit
6f65350269
@ -31,7 +31,6 @@ const PodcastManager = require('./managers/PodcastManager')
|
|||||||
const AudioMetadataMangaer = require('./managers/AudioMetadataManager')
|
const AudioMetadataMangaer = require('./managers/AudioMetadataManager')
|
||||||
const RssFeedManager = require('./managers/RssFeedManager')
|
const RssFeedManager = require('./managers/RssFeedManager')
|
||||||
const CronManager = require('./managers/CronManager')
|
const CronManager = require('./managers/CronManager')
|
||||||
const TaskManager = require('./managers/TaskManager')
|
|
||||||
const LibraryScanner = require('./scanner/LibraryScanner')
|
const LibraryScanner = require('./scanner/LibraryScanner')
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
@ -58,15 +57,14 @@ class Server {
|
|||||||
this.auth = new Auth()
|
this.auth = new Auth()
|
||||||
|
|
||||||
// Managers
|
// Managers
|
||||||
this.taskManager = new TaskManager()
|
|
||||||
this.notificationManager = new NotificationManager()
|
this.notificationManager = new NotificationManager()
|
||||||
this.emailManager = new EmailManager()
|
this.emailManager = new EmailManager()
|
||||||
this.backupManager = new BackupManager()
|
this.backupManager = new BackupManager()
|
||||||
this.logManager = new LogManager()
|
this.logManager = new LogManager()
|
||||||
this.abMergeManager = new AbMergeManager(this.taskManager)
|
this.abMergeManager = new AbMergeManager()
|
||||||
this.playbackSessionManager = new PlaybackSessionManager()
|
this.playbackSessionManager = new PlaybackSessionManager()
|
||||||
this.podcastManager = new PodcastManager(this.watcher, this.notificationManager, this.taskManager)
|
this.podcastManager = new PodcastManager(this.watcher, this.notificationManager)
|
||||||
this.audioMetadataManager = new AudioMetadataMangaer(this.taskManager)
|
this.audioMetadataManager = new AudioMetadataMangaer()
|
||||||
this.rssFeedManager = new RssFeedManager()
|
this.rssFeedManager = new RssFeedManager()
|
||||||
this.cronManager = new CronManager(this.podcastManager)
|
this.cronManager = new CronManager(this.podcastManager)
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@ const libraryItemFilters = require('../utils/queries/libraryItemFilters')
|
|||||||
const patternValidation = require('../libs/nodeCron/pattern-validation')
|
const patternValidation = require('../libs/nodeCron/pattern-validation')
|
||||||
const { isObject, getTitleIgnorePrefix } = require('../utils/index')
|
const { isObject, getTitleIgnorePrefix } = require('../utils/index')
|
||||||
|
|
||||||
|
const TaskManager = require('../managers/TaskManager')
|
||||||
|
|
||||||
//
|
//
|
||||||
// This is a controller for routes that don't have a home yet :(
|
// This is a controller for routes that don't have a home yet :(
|
||||||
//
|
//
|
||||||
@ -102,7 +104,7 @@ class MiscController {
|
|||||||
const includeArray = (req.query.include || '').split(',')
|
const includeArray = (req.query.include || '').split(',')
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
tasks: this.taskManager.tasks.map(t => t.toJSON())
|
tasks: TaskManager.tasks.map(t => t.toJSON())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeArray.includes('queue')) {
|
if (includeArray.includes('queue')) {
|
||||||
|
@ -4,14 +4,13 @@ const fs = require('../libs/fsExtra')
|
|||||||
|
|
||||||
const workerThreads = require('worker_threads')
|
const workerThreads = require('worker_threads')
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
|
const TaskManager = require('./TaskManager')
|
||||||
const Task = require('../objects/Task')
|
const Task = require('../objects/Task')
|
||||||
const { writeConcatFile } = require('../utils/ffmpegHelpers')
|
const { writeConcatFile } = require('../utils/ffmpegHelpers')
|
||||||
const toneHelpers = require('../utils/toneHelpers')
|
const toneHelpers = require('../utils/toneHelpers')
|
||||||
|
|
||||||
class AbMergeManager {
|
class AbMergeManager {
|
||||||
constructor(taskManager) {
|
constructor() {
|
||||||
this.taskManager = taskManager
|
|
||||||
|
|
||||||
this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items')
|
this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items')
|
||||||
|
|
||||||
this.pendingTasks = []
|
this.pendingTasks = []
|
||||||
@ -45,7 +44,7 @@ class AbMergeManager {
|
|||||||
}
|
}
|
||||||
const taskDescription = `Encoding audiobook "${libraryItem.media.metadata.title}" into a single m4b file.`
|
const taskDescription = `Encoding audiobook "${libraryItem.media.metadata.title}" into a single m4b file.`
|
||||||
task.setData('encode-m4b', 'Encoding M4b', taskDescription, false, taskData)
|
task.setData('encode-m4b', 'Encoding M4b', taskDescription, false, taskData)
|
||||||
this.taskManager.addTask(task)
|
TaskManager.addTask(task)
|
||||||
Logger.info(`Start m4b encode for ${libraryItem.id} - TaskId: ${task.id}`)
|
Logger.info(`Start m4b encode for ${libraryItem.id} - TaskId: ${task.id}`)
|
||||||
|
|
||||||
if (!await fs.pathExists(taskData.itemCachePath)) {
|
if (!await fs.pathExists(taskData.itemCachePath)) {
|
||||||
@ -234,7 +233,7 @@ class AbMergeManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.taskManager.taskFinished(task)
|
TaskManager.taskFinished(task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = AbMergeManager
|
module.exports = AbMergeManager
|
||||||
|
@ -7,12 +7,12 @@ const fs = require('../libs/fsExtra')
|
|||||||
|
|
||||||
const toneHelpers = require('../utils/toneHelpers')
|
const toneHelpers = require('../utils/toneHelpers')
|
||||||
|
|
||||||
|
const TaskManager = require('./TaskManager')
|
||||||
|
|
||||||
const Task = require('../objects/Task')
|
const Task = require('../objects/Task')
|
||||||
|
|
||||||
class AudioMetadataMangaer {
|
class AudioMetadataMangaer {
|
||||||
constructor(taskManager) {
|
constructor() {
|
||||||
this.taskManager = taskManager
|
|
||||||
|
|
||||||
this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items')
|
this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items')
|
||||||
|
|
||||||
this.MAX_CONCURRENT_TASKS = 1
|
this.MAX_CONCURRENT_TASKS = 1
|
||||||
@ -101,7 +101,7 @@ class AudioMetadataMangaer {
|
|||||||
|
|
||||||
async runMetadataEmbed(task) {
|
async runMetadataEmbed(task) {
|
||||||
this.tasksRunning.push(task)
|
this.tasksRunning.push(task)
|
||||||
this.taskManager.addTask(task)
|
TaskManager.addTask(task)
|
||||||
|
|
||||||
Logger.info(`[AudioMetadataManager] Starting metadata embed task`, task.description)
|
Logger.info(`[AudioMetadataManager] Starting metadata embed task`, task.description)
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ class AudioMetadataMangaer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleTaskFinished(task) {
|
handleTaskFinished(task) {
|
||||||
this.taskManager.taskFinished(task)
|
TaskManager.taskFinished(task)
|
||||||
this.tasksRunning = this.tasksRunning.filter(t => t.id !== task.id)
|
this.tasksRunning = this.tasksRunning.filter(t => t.id !== task.id)
|
||||||
|
|
||||||
if (this.tasksRunning.length < this.MAX_CONCURRENT_TASKS && this.tasksQueued.length) {
|
if (this.tasksRunning.length < this.MAX_CONCURRENT_TASKS && this.tasksQueued.length) {
|
||||||
|
@ -12,6 +12,8 @@ const opmlGenerator = require('../utils/generators/opmlGenerator')
|
|||||||
const prober = require('../utils/prober')
|
const prober = require('../utils/prober')
|
||||||
const ffmpegHelpers = require('../utils/ffmpegHelpers')
|
const ffmpegHelpers = require('../utils/ffmpegHelpers')
|
||||||
|
|
||||||
|
const TaskManager = require('./TaskManager')
|
||||||
|
|
||||||
const LibraryFile = require('../objects/files/LibraryFile')
|
const LibraryFile = require('../objects/files/LibraryFile')
|
||||||
const PodcastEpisodeDownload = require('../objects/PodcastEpisodeDownload')
|
const PodcastEpisodeDownload = require('../objects/PodcastEpisodeDownload')
|
||||||
const PodcastEpisode = require('../objects/entities/PodcastEpisode')
|
const PodcastEpisode = require('../objects/entities/PodcastEpisode')
|
||||||
@ -19,10 +21,9 @@ const AudioFile = require('../objects/files/AudioFile')
|
|||||||
const Task = require("../objects/Task")
|
const Task = require("../objects/Task")
|
||||||
|
|
||||||
class PodcastManager {
|
class PodcastManager {
|
||||||
constructor(watcher, notificationManager, taskManager) {
|
constructor(watcher, notificationManager) {
|
||||||
this.watcher = watcher
|
this.watcher = watcher
|
||||||
this.notificationManager = notificationManager
|
this.notificationManager = notificationManager
|
||||||
this.taskManager = taskManager
|
|
||||||
|
|
||||||
this.downloadQueue = []
|
this.downloadQueue = []
|
||||||
this.currentDownload = null
|
this.currentDownload = null
|
||||||
@ -76,7 +77,7 @@ class PodcastManager {
|
|||||||
libraryItemId: podcastEpisodeDownload.libraryItemId,
|
libraryItemId: podcastEpisodeDownload.libraryItemId,
|
||||||
}
|
}
|
||||||
task.setData('download-podcast-episode', 'Downloading Episode', taskDescription, false, taskData)
|
task.setData('download-podcast-episode', 'Downloading Episode', taskDescription, false, taskData)
|
||||||
this.taskManager.addTask(task)
|
TaskManager.addTask(task)
|
||||||
|
|
||||||
SocketAuthority.emitter('episode_download_started', podcastEpisodeDownload.toJSONForClient())
|
SocketAuthority.emitter('episode_download_started', podcastEpisodeDownload.toJSONForClient())
|
||||||
this.currentDownload = podcastEpisodeDownload
|
this.currentDownload = podcastEpisodeDownload
|
||||||
@ -128,7 +129,7 @@ class PodcastManager {
|
|||||||
this.currentDownload.setFinished(false)
|
this.currentDownload.setFinished(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.taskManager.taskFinished(task)
|
TaskManager.taskFinished(task)
|
||||||
|
|
||||||
SocketAuthority.emitter('episode_download_finished', this.currentDownload.toJSONForClient())
|
SocketAuthority.emitter('episode_download_finished', this.currentDownload.toJSONForClient())
|
||||||
SocketAuthority.emitter('episode_download_queue_updated', this.getDownloadQueueDetails())
|
SocketAuthority.emitter('episode_download_queue_updated', this.getDownloadQueueDetails())
|
||||||
|
@ -1,15 +1,27 @@
|
|||||||
const SocketAuthority = require('../SocketAuthority')
|
const SocketAuthority = require('../SocketAuthority')
|
||||||
|
const Task = require('../objects/Task')
|
||||||
|
|
||||||
class TaskManager {
|
class TaskManager {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
/** @type {Task[]} */
|
||||||
this.tasks = []
|
this.tasks = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add task and emit socket task_started event
|
||||||
|
*
|
||||||
|
* @param {Task} task
|
||||||
|
*/
|
||||||
addTask(task) {
|
addTask(task) {
|
||||||
this.tasks.push(task)
|
this.tasks.push(task)
|
||||||
SocketAuthority.emitter('task_started', task.toJSON())
|
SocketAuthority.emitter('task_started', task.toJSON())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove task and emit task_finished event
|
||||||
|
*
|
||||||
|
* @param {Task} task
|
||||||
|
*/
|
||||||
taskFinished(task) {
|
taskFinished(task) {
|
||||||
if (this.tasks.some(t => t.id === task.id)) {
|
if (this.tasks.some(t => t.id === task.id)) {
|
||||||
this.tasks = this.tasks.filter(t => t.id !== task.id)
|
this.tasks = this.tasks.filter(t => t.id !== task.id)
|
||||||
@ -17,4 +29,4 @@ class TaskManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = TaskManager
|
module.exports = new TaskManager()
|
@ -2,19 +2,30 @@ const uuidv4 = require("uuid").v4
|
|||||||
|
|
||||||
class Task {
|
class Task {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
/** @type {string} */
|
||||||
this.id = null
|
this.id = null
|
||||||
|
/** @type {string} */
|
||||||
this.action = null // e.g. embed-metadata, encode-m4b, etc
|
this.action = null // e.g. embed-metadata, encode-m4b, etc
|
||||||
|
/** @type {Object} custom data */
|
||||||
this.data = null // additional info for the action like libraryItemId
|
this.data = null // additional info for the action like libraryItemId
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
this.title = null
|
this.title = null
|
||||||
|
/** @type {string} */
|
||||||
this.description = null
|
this.description = null
|
||||||
|
/** @type {string} */
|
||||||
this.error = null
|
this.error = null
|
||||||
this.showSuccess = false // If true client side should keep the task visible after success
|
/** @type {boolean} client should keep the task visible after success */
|
||||||
|
this.showSuccess = false
|
||||||
|
|
||||||
|
/** @type {boolean} */
|
||||||
this.isFailed = false
|
this.isFailed = false
|
||||||
|
/** @type {boolean} */
|
||||||
this.isFinished = false
|
this.isFinished = false
|
||||||
|
|
||||||
|
/** @type {number} */
|
||||||
this.startedAt = null
|
this.startedAt = null
|
||||||
|
/** @type {number} */
|
||||||
this.finishedAt = null
|
this.finishedAt = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +45,15 @@ class Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set initial task data
|
||||||
|
*
|
||||||
|
* @param {string} action
|
||||||
|
* @param {string} title
|
||||||
|
* @param {string} description
|
||||||
|
* @param {boolean} showSuccess
|
||||||
|
* @param {Object} [data]
|
||||||
|
*/
|
||||||
setData(action, title, description, showSuccess, data = {}) {
|
setData(action, title, description, showSuccess, data = {}) {
|
||||||
this.id = uuidv4()
|
this.id = uuidv4()
|
||||||
this.action = action
|
this.action = action
|
||||||
@ -44,6 +64,11 @@ class Task {
|
|||||||
this.startedAt = Date.now()
|
this.startedAt = Date.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set task as failed
|
||||||
|
*
|
||||||
|
* @param {string} message error message
|
||||||
|
*/
|
||||||
setFailed(message) {
|
setFailed(message) {
|
||||||
this.error = message
|
this.error = message
|
||||||
this.isFailed = true
|
this.isFailed = true
|
||||||
@ -51,6 +76,11 @@ class Task {
|
|||||||
this.setFinished()
|
this.setFinished()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set task as finished
|
||||||
|
*
|
||||||
|
* @param {string} [newDescription] update description
|
||||||
|
*/
|
||||||
setFinished(newDescription = null) {
|
setFinished(newDescription = null) {
|
||||||
if (newDescription) {
|
if (newDescription) {
|
||||||
this.description = newDescription
|
this.description = newDescription
|
||||||
|
@ -46,7 +46,6 @@ class ApiRouter {
|
|||||||
this.cronManager = Server.cronManager
|
this.cronManager = Server.cronManager
|
||||||
this.notificationManager = Server.notificationManager
|
this.notificationManager = Server.notificationManager
|
||||||
this.emailManager = Server.emailManager
|
this.emailManager = Server.emailManager
|
||||||
this.taskManager = Server.taskManager
|
|
||||||
|
|
||||||
this.router = express()
|
this.router = express()
|
||||||
this.router.disable('x-powered-by')
|
this.router.disable('x-powered-by')
|
||||||
|
Loading…
Reference in New Issue
Block a user