switch task creation to api posts

This commit is contained in:
simon 2023-03-23 11:28:42 +07:00
parent f304c2eb02
commit 0e726af2de
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 15 additions and 94 deletions

View File

@ -9,19 +9,9 @@ from home.src.download.subscriptions import (
PlaylistSubscription, PlaylistSubscription,
) )
from home.src.index.playlist import YoutubePlaylist from home.src.index.playlist import YoutubePlaylist
from home.src.ta.ta_redis import RedisArchivist, RedisQueue from home.src.ta.ta_redis import RedisArchivist
from home.src.ta.urlparser import Parser from home.src.ta.urlparser import Parser
from home.tasks import ( from home.tasks import run_restore_backup, subscribe_to
download_pending,
kill_dl,
re_sync_thumbs,
rescan_filesystem,
run_backup,
run_manual_import,
run_restore_backup,
subscribe_to,
update_subscribed,
)
class PostData: class PostData:
@ -46,20 +36,13 @@ class PostData:
exec_map = { exec_map = {
"change_view": self._change_view, "change_view": self._change_view,
"change_grid": self._change_grid, "change_grid": self._change_grid,
"rescan_pending": self._rescan_pending,
"dl_pending": self._dl_pending,
"queue": self._queue_handler,
"unsubscribe": self._unsubscribe, "unsubscribe": self._unsubscribe,
"subscribe": self._subscribe, "subscribe": self._subscribe,
"sort_order": self._sort_order, "sort_order": self._sort_order,
"hide_watched": self._hide_watched, "hide_watched": self._hide_watched,
"show_subed_only": self._show_subed_only, "show_subed_only": self._show_subed_only,
"show_ignored_only": self._show_ignored_only, "show_ignored_only": self._show_ignored_only,
"manual-import": self._manual_import,
"re-embed": self._re_embed,
"db-backup": self._db_backup,
"db-restore": self._db_restore, "db-restore": self._db_restore,
"fs-rescan": self._fs_rescan,
"delete-playlist": self._delete_playlist, "delete-playlist": self._delete_playlist,
} }
@ -84,39 +67,6 @@ class PostData:
RedisArchivist().set_message(key, {"status": grid_items}) RedisArchivist().set_message(key, {"status": grid_items})
return {"success": True} return {"success": True}
@staticmethod
def _rescan_pending():
"""look for new items in subscribed channels"""
print("rescan subscribed channels")
update_subscribed.delay()
return {"success": True}
@staticmethod
def _dl_pending():
"""start the download queue"""
print("download pending")
running = download_pending.delay()
task_id = running.id
print(f"{task_id}: set task id")
RedisArchivist().set_message("dl_queue_id", task_id)
return {"success": True}
def _queue_handler(self):
"""queue controls from frontend"""
to_execute = self.exec_val
if to_execute == "stop":
print("stopping download queue")
RedisQueue(queue_name="dl_queue").clear()
elif to_execute == "kill":
task_id = RedisArchivist().get_message("dl_queue_id")
if not isinstance(task_id, str):
task_id = False
else:
print("brutally killing " + task_id)
kill_dl(task_id)
return {"success": True}
def _unsubscribe(self): def _unsubscribe(self):
"""unsubscribe from channels or playlists""" """unsubscribe from channels or playlists"""
id_unsub = self.exec_val id_unsub = self.exec_val
@ -183,27 +133,6 @@ class PostData:
RedisArchivist().set_message(key, value) RedisArchivist().set_message(key, value)
return {"success": True} return {"success": True}
@staticmethod
def _manual_import():
"""run manual import from settings page"""
print("starting manual import")
run_manual_import.delay()
return {"success": True}
@staticmethod
def _re_embed():
"""rewrite thumbnails into media files"""
print("start video thumbnail embed process")
re_sync_thumbs.delay()
return {"success": True}
@staticmethod
def _db_backup():
"""backup es to zip from settings page"""
print("backing up database")
run_backup.delay("manual")
return {"success": True}
def _db_restore(self): def _db_restore(self):
"""restore es zip from settings page""" """restore es zip from settings page"""
print("restoring index from backup zip") print("restoring index from backup zip")
@ -211,13 +140,6 @@ class PostData:
run_restore_backup.delay(filename) run_restore_backup.delay(filename)
return {"success": True} return {"success": True}
@staticmethod
def _fs_rescan():
"""start file system rescan task"""
print("start filesystem scan")
rescan_filesystem.delay()
return {"success": True}
def _delete_playlist(self): def _delete_playlist(self):
"""delete playlist, only metadata or incl all videos""" """delete playlist, only metadata or incl all videos"""
playlist_dict = self.exec_val playlist_dict = self.exec_val

View File

@ -23,8 +23,7 @@ from home.src.index.filesystem import Filesystem
from home.src.index.manual import ImportFolderScanner from home.src.index.manual import ImportFolderScanner
from home.src.index.reindex import Reindex, ReindexManual, ReindexOutdated from home.src.index.reindex import Reindex, ReindexManual, ReindexOutdated
from home.src.ta.config import AppConfig, ReleaseVersion, ScheduleBuilder from home.src.ta.config import AppConfig, ReleaseVersion, ScheduleBuilder
from home.src.ta.helper import clear_dl_cache from home.src.ta.ta_redis import RedisArchivist
from home.src.ta.ta_redis import RedisArchivist, RedisQueue
from home.src.ta.task_manager import TaskManager from home.src.ta.task_manager import TaskManager
CONFIG = AppConfig().config CONFIG = AppConfig().config

View File

@ -167,18 +167,18 @@ function reindex(button) {
// download page buttons // download page buttons
function rescanPending() { function rescanPending() {
let payload = JSON.stringify({ rescan_pending: true }); let apiEndpoint = '/api/task-name/update_subscribed/';
apiRequest(apiEndpoint, 'POST');
animate('rescan-icon', 'rotate-img'); animate('rescan-icon', 'rotate-img');
sendPost(payload);
setTimeout(function () { setTimeout(function () {
checkMessages(); checkMessages();
}, 500); }, 500);
} }
function dlPending() { function dlPending() {
let payload = JSON.stringify({ dl_pending: true }); let apiEndpoint = '/api/task-name/download_pending/';
apiRequest(apiEndpoint, 'POST');
animate('download-icon', 'bounce-img'); animate('download-icon', 'bounce-img');
sendPost(payload);
setTimeout(function () { setTimeout(function () {
checkMessages(); checkMessages();
}, 500); }, 500);
@ -244,8 +244,8 @@ function killTask(icon) {
// settings page buttons // settings page buttons
function manualImport() { function manualImport() {
let payload = JSON.stringify({ 'manual-import': true }); let apiEndpoint = '/api/task-name/manual_import/';
sendPost(payload); apiRequest(apiEndpoint, 'POST');
// clear button // clear button
let message = document.createElement('p'); let message = document.createElement('p');
message.innerText = 'processing import'; message.innerText = 'processing import';
@ -259,8 +259,8 @@ function manualImport() {
} }
function reEmbed() { function reEmbed() {
let payload = JSON.stringify({ 're-embed': true }); let apiEndpoint = '/api/task-name/resync_thumbs/';
sendPost(payload); apiRequest(apiEndpoint, 'POST');
// clear button // clear button
let message = document.createElement('p'); let message = document.createElement('p');
message.innerText = 'processing thumbnails'; message.innerText = 'processing thumbnails';
@ -274,8 +274,8 @@ function reEmbed() {
} }
function dbBackup() { function dbBackup() {
let payload = JSON.stringify({ 'db-backup': true }); let apiEndpoint = '/api/task-name/run_backup/';
sendPost(payload); apiRequest(apiEndpoint, 'POST');
// clear button // clear button
let message = document.createElement('p'); let message = document.createElement('p');
message.innerText = 'backing up archive'; message.innerText = 'backing up archive';
@ -305,8 +305,8 @@ function dbRestore(button) {
} }
function fsRescan() { function fsRescan() {
let payload = JSON.stringify({ 'fs-rescan': true }); let apiEndpoint = '/api/task-name/rescan_filesystem/';
sendPost(payload); apiRequest(apiEndpoint, 'POST');
// clear button // clear button
let message = document.createElement('p'); let message = document.createElement('p');
message.innerText = 'File system scan in progress'; message.innerText = 'File system scan in progress';