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")
|
LOG: logging.Logger = logging.getLogger("Events")
|
||||||
|
|
||||||
|
|
||||||
class Events:
|
class Events:
|
||||||
"""
|
"""
|
||||||
The events that can be emitted.
|
The events that can be emitted.
|
||||||
|
|
@ -22,30 +23,32 @@ class Events:
|
||||||
SHUTDOWN = "shutdown"
|
SHUTDOWN = "shutdown"
|
||||||
|
|
||||||
ADDED = "added"
|
ADDED = "added"
|
||||||
|
UPDATE = "update"
|
||||||
UPDATED = "updated"
|
UPDATED = "updated"
|
||||||
COMPLETED = "completed"
|
COMPLETED = "completed"
|
||||||
CANCELLED = "cancelled"
|
CANCELLED = "cancelled"
|
||||||
CLEARED = "cleared"
|
CLEARED = "cleared"
|
||||||
ERROR = "error"
|
CONNECTED = "connected"
|
||||||
|
STATUS = "status"
|
||||||
|
|
||||||
LOG_INFO = "log_info"
|
LOG_INFO = "log_info"
|
||||||
LOG_WARNING = "log_warning"
|
LOG_WARNING = "log_warning"
|
||||||
LOG_ERROR = "log_error"
|
LOG_ERROR = "log_error"
|
||||||
LOG_SUCCESS = "log_success"
|
LOG_SUCCESS = "log_success"
|
||||||
|
|
||||||
INITIAL_DATA = "initial_data"
|
|
||||||
ITEM_DELETE = "item_delete"
|
ITEM_DELETE = "item_delete"
|
||||||
ITEM_CANCEL = "item_cancel"
|
ITEM_CANCEL = "item_cancel"
|
||||||
ITEM_ERROR = "item_error"
|
ITEM_ERROR = "item_error"
|
||||||
STATUS = "status"
|
|
||||||
CLI_CLOSE = "cli_close"
|
|
||||||
CLI_OUTPUT = "cli_output"
|
|
||||||
UPDATE = "update"
|
|
||||||
TEST = "test"
|
TEST = "test"
|
||||||
ADD_URL = "add_url"
|
ADD_URL = "add_url"
|
||||||
|
|
||||||
CLI_POST = "cli_post"
|
|
||||||
PAUSED = "paused"
|
PAUSED = "paused"
|
||||||
|
|
||||||
|
CLI_POST = "cli_post"
|
||||||
|
CLI_CLOSE = "cli_close"
|
||||||
|
CLI_OUTPUT = "cli_output"
|
||||||
|
|
||||||
TASKS_ADD = "task_add"
|
TASKS_ADD = "task_add"
|
||||||
TASK_DISPATCHED = "task_dispatched"
|
TASK_DISPATCHED = "task_dispatched"
|
||||||
TASK_FINISHED = "task_finished"
|
TASK_FINISHED = "task_finished"
|
||||||
|
|
@ -53,6 +56,7 @@ class Events:
|
||||||
|
|
||||||
PRESETS_ADD = "presets_add"
|
PRESETS_ADD = "presets_add"
|
||||||
PRESETS_UPDATE = "presets_update"
|
PRESETS_UPDATE = "presets_update"
|
||||||
|
|
||||||
SCHEDULE_ADD = "schedule_add"
|
SCHEDULE_ADD = "schedule_add"
|
||||||
|
|
||||||
CONDITIONS_ADD = "conditions_add"
|
CONDITIONS_ADD = "conditions_add"
|
||||||
|
|
@ -82,9 +86,8 @@ class Events:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return [
|
return [
|
||||||
Events.INITIAL_DATA,
|
Events.CONNECTED,
|
||||||
Events.ADDED,
|
Events.ADDED,
|
||||||
Events.ERROR,
|
|
||||||
Events.LOG_INFO,
|
Events.LOG_INFO,
|
||||||
Events.LOG_WARNING,
|
Events.LOG_WARNING,
|
||||||
Events.LOG_ERROR,
|
Events.LOG_ERROR,
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,6 @@ class Target:
|
||||||
class NotificationEvents:
|
class NotificationEvents:
|
||||||
ADDED = Events.ADDED
|
ADDED = Events.ADDED
|
||||||
COMPLETED = Events.COMPLETED
|
COMPLETED = Events.COMPLETED
|
||||||
ERROR = Events.ERROR
|
|
||||||
CANCELLED = Events.CANCELLED
|
CANCELLED = Events.CANCELLED
|
||||||
CLEARED = Events.CLEARED
|
CLEARED = Events.CLEARED
|
||||||
LOG_INFO = Events.LOG_INFO
|
LOG_INFO = Events.LOG_INFO
|
||||||
|
|
@ -308,10 +307,17 @@ class Notification(metaclass=Singleton):
|
||||||
msg = "Invalid notification target. Invalid 'on' event list found."
|
msg = "Invalid notification target. Invalid 'on' event list found."
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
removed_events = []
|
||||||
|
all_events = NotificationEvents.get_events().values()
|
||||||
for e in target["on"]:
|
for e in target["on"]:
|
||||||
if e not in NotificationEvents.get_events().values():
|
if e not in all_events:
|
||||||
msg = f"Invalid notification target. Invalid event '{e}' found."
|
removed_events.append(e)
|
||||||
raise ValueError(msg)
|
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 "headers" in target["request"]:
|
||||||
if not isinstance(target["request"]["headers"], list):
|
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()]
|
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")
|
@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:
|
if not isinstance(data, str) or not data:
|
||||||
await notify.emit(
|
await notify.emit(
|
||||||
Events.ERROR,
|
Events.LOG_ERROR,
|
||||||
title="Subscription Error",
|
title="Subscription Error",
|
||||||
message="Invalid event type was expecting a string.",
|
message="Invalid event type was expecting a string.",
|
||||||
to=sid,
|
to=sid,
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,9 @@ async def item_cancel(queue: DownloadQueue, notify: EventBus, sid: str, data: st
|
||||||
status = await queue.cancel([data])
|
status = await queue.cancel([data])
|
||||||
status.update({"identifier": 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")
|
@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('connect', () => isConnected.value = true);
|
||||||
socket.value.on('disconnect', () => isConnected.value = false);
|
socket.value.on('disconnect', () => isConnected.value = false);
|
||||||
|
|
||||||
socket.value.on('initial_data', stream => {
|
socket.value.on('connected', stream => {
|
||||||
const json = JSON.parse(stream)
|
const json = JSON.parse(stream)
|
||||||
|
|
||||||
config.setAll({
|
config.setAll({
|
||||||
|
|
@ -51,11 +51,6 @@ export const useSocketStore = defineStore('socket', () => {
|
||||||
toast.success(`Item queued: ${ag(stateStore.get('queue', json.data._id, {}), 'title')}`);
|
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 => {
|
['log_info', 'log_success', 'log_warning', 'log_error'].forEach(event => socket.value?.on(event, stream => {
|
||||||
const json = JSON.parse(stream);
|
const json = JSON.parse(stream);
|
||||||
const message = json?.message || json?.data?.message;
|
const message = json?.message || json?.data?.message;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue