removed event type ERROR and migrated it's uses to LOG_ERROR
This commit is contained in:
parent
138a497703
commit
0f7f22bdbf
5 changed files with 34 additions and 22 deletions
|
|
@ -11,6 +11,7 @@ from .Singleton import Singleton
|
|||
|
||||
LOG: logging.Logger = logging.getLogger("Events")
|
||||
|
||||
|
||||
class Events:
|
||||
"""
|
||||
The events that can be emitted.
|
||||
|
|
@ -22,30 +23,32 @@ class Events:
|
|||
SHUTDOWN = "shutdown"
|
||||
|
||||
ADDED = "added"
|
||||
UPDATE = "update"
|
||||
UPDATED = "updated"
|
||||
COMPLETED = "completed"
|
||||
CANCELLED = "cancelled"
|
||||
CLEARED = "cleared"
|
||||
ERROR = "error"
|
||||
CONNECTED = "connected"
|
||||
STATUS = "status"
|
||||
|
||||
LOG_INFO = "log_info"
|
||||
LOG_WARNING = "log_warning"
|
||||
LOG_ERROR = "log_error"
|
||||
LOG_SUCCESS = "log_success"
|
||||
|
||||
INITIAL_DATA = "initial_data"
|
||||
ITEM_DELETE = "item_delete"
|
||||
ITEM_CANCEL = "item_cancel"
|
||||
ITEM_ERROR = "item_error"
|
||||
STATUS = "status"
|
||||
CLI_CLOSE = "cli_close"
|
||||
CLI_OUTPUT = "cli_output"
|
||||
UPDATE = "update"
|
||||
|
||||
TEST = "test"
|
||||
ADD_URL = "add_url"
|
||||
|
||||
CLI_POST = "cli_post"
|
||||
PAUSED = "paused"
|
||||
|
||||
CLI_POST = "cli_post"
|
||||
CLI_CLOSE = "cli_close"
|
||||
CLI_OUTPUT = "cli_output"
|
||||
|
||||
TASKS_ADD = "task_add"
|
||||
TASK_DISPATCHED = "task_dispatched"
|
||||
TASK_FINISHED = "task_finished"
|
||||
|
|
@ -53,6 +56,7 @@ class Events:
|
|||
|
||||
PRESETS_ADD = "presets_add"
|
||||
PRESETS_UPDATE = "presets_update"
|
||||
|
||||
SCHEDULE_ADD = "schedule_add"
|
||||
|
||||
CONDITIONS_ADD = "conditions_add"
|
||||
|
|
@ -82,9 +86,8 @@ class Events:
|
|||
|
||||
"""
|
||||
return [
|
||||
Events.INITIAL_DATA,
|
||||
Events.CONNECTED,
|
||||
Events.ADDED,
|
||||
Events.ERROR,
|
||||
Events.LOG_INFO,
|
||||
Events.LOG_WARNING,
|
||||
Events.LOG_ERROR,
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ class Target:
|
|||
class NotificationEvents:
|
||||
ADDED = Events.ADDED
|
||||
COMPLETED = Events.COMPLETED
|
||||
ERROR = Events.ERROR
|
||||
CANCELLED = Events.CANCELLED
|
||||
CLEARED = Events.CLEARED
|
||||
LOG_INFO = Events.LOG_INFO
|
||||
|
|
@ -308,10 +307,17 @@ class Notification(metaclass=Singleton):
|
|||
msg = "Invalid notification target. Invalid 'on' event list found."
|
||||
raise ValueError(msg)
|
||||
|
||||
removed_events = []
|
||||
all_events = NotificationEvents.get_events().values()
|
||||
for e in target["on"]:
|
||||
if e not in NotificationEvents.get_events().values():
|
||||
msg = f"Invalid notification target. Invalid event '{e}' found."
|
||||
raise ValueError(msg)
|
||||
if e not in all_events:
|
||||
removed_events.append(e)
|
||||
target["on"].remove(e)
|
||||
continue
|
||||
|
||||
if len(removed_events) > 0 and len(target["on"]) < 1:
|
||||
msg: str = f"Invalid notification target. Invalid events '{', '.join(removed_events)}' found."
|
||||
raise ValueError(msg)
|
||||
|
||||
if "headers" in target["request"]:
|
||||
if not isinstance(target["request"]["headers"], list):
|
||||
|
|
|
|||
|
|
@ -31,7 +31,13 @@ async def connect(config: Config, queue: DownloadQueue, notify: EventBus, sid: s
|
|||
|
||||
data["folders"] = [folder.name for folder in Path(config.download_path).iterdir() if folder.is_dir()]
|
||||
|
||||
await notify.emit(Events.INITIAL_DATA, data=data, to=sid)
|
||||
await notify.emit(
|
||||
Events.CONNECTED,
|
||||
data=data,
|
||||
title="Client connected",
|
||||
message=f"Client '{sid}' connected.",
|
||||
to=sid,
|
||||
)
|
||||
|
||||
|
||||
@route(RouteType.SOCKET, "disconnect", "socket_disconnect")
|
||||
|
|
@ -67,7 +73,7 @@ async def subscribe(config: Config, notify: EventBus, sio: socketio.AsyncServer,
|
|||
"""
|
||||
if not isinstance(data, str) or not data:
|
||||
await notify.emit(
|
||||
Events.ERROR,
|
||||
Events.LOG_ERROR,
|
||||
title="Subscription Error",
|
||||
message="Invalid event type was expecting a string.",
|
||||
to=sid,
|
||||
|
|
|
|||
|
|
@ -80,7 +80,9 @@ async def item_cancel(queue: DownloadQueue, notify: EventBus, sid: str, data: st
|
|||
status = await queue.cancel([data])
|
||||
status.update({"identifier": data})
|
||||
|
||||
await notify.emit(Events.ITEM_CANCEL, data=status)
|
||||
await notify.emit(
|
||||
Events.ITEM_CANCEL, data=status, title="Item Cancelled", message=f"Item '{data}': has been cancelled."
|
||||
)
|
||||
|
||||
|
||||
@route(RouteType.SOCKET, "item_delete", "item_delete")
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export const useSocketStore = defineStore('socket', () => {
|
|||
socket.value.on('connect', () => isConnected.value = true);
|
||||
socket.value.on('disconnect', () => isConnected.value = false);
|
||||
|
||||
socket.value.on('initial_data', stream => {
|
||||
socket.value.on('connected', stream => {
|
||||
const json = JSON.parse(stream)
|
||||
|
||||
config.setAll({
|
||||
|
|
@ -51,11 +51,6 @@ export const useSocketStore = defineStore('socket', () => {
|
|||
toast.success(`Item queued: ${ag(stateStore.get('queue', json.data._id, {}), 'title')}`);
|
||||
});
|
||||
|
||||
socket.value.on('error', stream => {
|
||||
const json = JSON.parse(stream);
|
||||
toast.error(`${json.data?.id}: ${json?.message || json?.data?.message}`, json.data || {});
|
||||
});
|
||||
|
||||
['log_info', 'log_success', 'log_warning', 'log_error'].forEach(event => socket.value?.on(event, stream => {
|
||||
const json = JSON.parse(stream);
|
||||
const message = json?.message || json?.data?.message;
|
||||
|
|
|
|||
Loading…
Reference in a new issue