mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-01-02 00:59:37 +00:00
Update:JSDocs for task manager
This commit is contained in:
parent
5644a40a03
commit
6f65350269
8 changed files with 64 additions and 23 deletions
|
|
@ -4,14 +4,13 @@ const fs = require('../libs/fsExtra')
|
|||
|
||||
const workerThreads = require('worker_threads')
|
||||
const Logger = require('../Logger')
|
||||
const TaskManager = require('./TaskManager')
|
||||
const Task = require('../objects/Task')
|
||||
const { writeConcatFile } = require('../utils/ffmpegHelpers')
|
||||
const toneHelpers = require('../utils/toneHelpers')
|
||||
|
||||
class AbMergeManager {
|
||||
constructor(taskManager) {
|
||||
this.taskManager = taskManager
|
||||
|
||||
constructor() {
|
||||
this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items')
|
||||
|
||||
this.pendingTasks = []
|
||||
|
|
@ -45,7 +44,7 @@ class AbMergeManager {
|
|||
}
|
||||
const taskDescription = `Encoding audiobook "${libraryItem.media.metadata.title}" into a single m4b file.`
|
||||
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}`)
|
||||
|
||||
if (!await fs.pathExists(taskData.itemCachePath)) {
|
||||
|
|
@ -234,7 +233,7 @@ class AbMergeManager {
|
|||
}
|
||||
}
|
||||
|
||||
this.taskManager.taskFinished(task)
|
||||
TaskManager.taskFinished(task)
|
||||
}
|
||||
}
|
||||
module.exports = AbMergeManager
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@ const fs = require('../libs/fsExtra')
|
|||
|
||||
const toneHelpers = require('../utils/toneHelpers')
|
||||
|
||||
const TaskManager = require('./TaskManager')
|
||||
|
||||
const Task = require('../objects/Task')
|
||||
|
||||
class AudioMetadataMangaer {
|
||||
constructor(taskManager) {
|
||||
this.taskManager = taskManager
|
||||
|
||||
constructor() {
|
||||
this.itemsCacheDir = Path.join(global.MetadataPath, 'cache/items')
|
||||
|
||||
this.MAX_CONCURRENT_TASKS = 1
|
||||
|
|
@ -101,7 +101,7 @@ class AudioMetadataMangaer {
|
|||
|
||||
async runMetadataEmbed(task) {
|
||||
this.tasksRunning.push(task)
|
||||
this.taskManager.addTask(task)
|
||||
TaskManager.addTask(task)
|
||||
|
||||
Logger.info(`[AudioMetadataManager] Starting metadata embed task`, task.description)
|
||||
|
||||
|
|
@ -176,7 +176,7 @@ class AudioMetadataMangaer {
|
|||
}
|
||||
|
||||
handleTaskFinished(task) {
|
||||
this.taskManager.taskFinished(task)
|
||||
TaskManager.taskFinished(task)
|
||||
this.tasksRunning = this.tasksRunning.filter(t => t.id !== task.id)
|
||||
|
||||
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 ffmpegHelpers = require('../utils/ffmpegHelpers')
|
||||
|
||||
const TaskManager = require('./TaskManager')
|
||||
|
||||
const LibraryFile = require('../objects/files/LibraryFile')
|
||||
const PodcastEpisodeDownload = require('../objects/PodcastEpisodeDownload')
|
||||
const PodcastEpisode = require('../objects/entities/PodcastEpisode')
|
||||
|
|
@ -19,10 +21,9 @@ const AudioFile = require('../objects/files/AudioFile')
|
|||
const Task = require("../objects/Task")
|
||||
|
||||
class PodcastManager {
|
||||
constructor(watcher, notificationManager, taskManager) {
|
||||
constructor(watcher, notificationManager) {
|
||||
this.watcher = watcher
|
||||
this.notificationManager = notificationManager
|
||||
this.taskManager = taskManager
|
||||
|
||||
this.downloadQueue = []
|
||||
this.currentDownload = null
|
||||
|
|
@ -76,7 +77,7 @@ class PodcastManager {
|
|||
libraryItemId: podcastEpisodeDownload.libraryItemId,
|
||||
}
|
||||
task.setData('download-podcast-episode', 'Downloading Episode', taskDescription, false, taskData)
|
||||
this.taskManager.addTask(task)
|
||||
TaskManager.addTask(task)
|
||||
|
||||
SocketAuthority.emitter('episode_download_started', podcastEpisodeDownload.toJSONForClient())
|
||||
this.currentDownload = podcastEpisodeDownload
|
||||
|
|
@ -128,7 +129,7 @@ class PodcastManager {
|
|||
this.currentDownload.setFinished(false)
|
||||
}
|
||||
|
||||
this.taskManager.taskFinished(task)
|
||||
TaskManager.taskFinished(task)
|
||||
|
||||
SocketAuthority.emitter('episode_download_finished', this.currentDownload.toJSONForClient())
|
||||
SocketAuthority.emitter('episode_download_queue_updated', this.getDownloadQueueDetails())
|
||||
|
|
|
|||
|
|
@ -1,15 +1,27 @@
|
|||
const SocketAuthority = require('../SocketAuthority')
|
||||
const Task = require('../objects/Task')
|
||||
|
||||
class TaskManager {
|
||||
constructor() {
|
||||
/** @type {Task[]} */
|
||||
this.tasks = []
|
||||
}
|
||||
|
||||
/**
|
||||
* Add task and emit socket task_started event
|
||||
*
|
||||
* @param {Task} task
|
||||
*/
|
||||
addTask(task) {
|
||||
this.tasks.push(task)
|
||||
SocketAuthority.emitter('task_started', task.toJSON())
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove task and emit task_finished event
|
||||
*
|
||||
* @param {Task} task
|
||||
*/
|
||||
taskFinished(task) {
|
||||
if (this.tasks.some(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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue