refac
This commit is contained in:
1 parent
35f8bf97e3
commit
b5c43968db
32 files changed
+2251
-120
No files matched your search
@@ -26,6 +26,7 @@ from zoneinfo import ZoneInfo
|
||||
from dateutil.rrule import rrulestr
|
||||
from fastapi import Request
|
||||
from open_webui.constants import ERROR_MESSAGES
|
||||
from open_webui.events import EVENTS, publish_event
|
||||
from open_webui.internal.db import get_async_db
|
||||
from open_webui.models.automations import AutomationModel, AutomationRuns, Automations
|
||||
from open_webui.models.chats import ChatForm, Chats
|
||||
@@ -357,6 +358,12 @@ async def execute_automation(app, automation: AutomationModel) -> None:
|
||||
user = await Users.get_user_by_id(automation.user_id)
|
||||
if not user:
|
||||
await _record_run(automation.id, 'error', error='User not found')
|
||||
await publish_event(
|
||||
app,
|
||||
EVENTS.AUTOMATION_RUN_FAILED,
|
||||
subject_id=automation.id,
|
||||
data={'name': automation.name, 'error': 'User not found'},
|
||||
)
|
||||
return
|
||||
|
||||
# Re-gate the rehydrated owner: a demoted/deactivated or de-permissioned owner must not run.
|
||||
@@ -366,7 +373,15 @@ async def execute_automation(app, automation: AutomationModel) -> None:
|
||||
user.role != 'admin'
|
||||
and not await has_permission(user.id, 'features.automations', await Config.get('user.permissions'))
|
||||
):
|
||||
await _record_run(automation.id, 'error', error='Owner no longer permitted to run automations')
|
||||
error = 'Owner no longer permitted to run automations'
|
||||
await _record_run(automation.id, 'error', error=error)
|
||||
await publish_event(
|
||||
app,
|
||||
EVENTS.AUTOMATION_RUN_FAILED,
|
||||
actor=user,
|
||||
subject_id=automation.id,
|
||||
data={'name': automation.name, 'error': error},
|
||||
)
|
||||
return
|
||||
|
||||
prompt = await prompt_template(automation.data['prompt'], user)
|
||||
@@ -418,7 +433,15 @@ async def execute_automation(app, automation: AutomationModel) -> None:
|
||||
)
|
||||
|
||||
if not chat:
|
||||
await _record_run(automation.id, 'error', error='Failed to create chat')
|
||||
error = 'Failed to create chat'
|
||||
await _record_run(automation.id, 'error', error=error)
|
||||
await publish_event(
|
||||
app,
|
||||
EVENTS.AUTOMATION_RUN_FAILED,
|
||||
actor=user,
|
||||
subject_id=automation.id,
|
||||
data={'name': automation.name, 'error': error},
|
||||
)
|
||||
return
|
||||
|
||||
# Notify frontend to refresh chat list
|
||||
@@ -488,10 +511,24 @@ async def execute_automation(app, automation: AutomationModel) -> None:
|
||||
)
|
||||
|
||||
await _record_run(automation.id, 'success', chat_id=chat.id)
|
||||
await publish_event(
|
||||
app,
|
||||
EVENTS.AUTOMATION_RUN_COMPLETED,
|
||||
actor=user,
|
||||
subject_id=automation.id,
|
||||
data={'name': automation.name, 'chat_id': chat.id},
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
log.exception(f'Automation {automation.id} failed')
|
||||
await _record_run(automation.id, 'error', error=str(e)[:4000])
|
||||
error = str(e)[:4000]
|
||||
await _record_run(automation.id, 'error', error=error)
|
||||
await publish_event(
|
||||
app,
|
||||
EVENTS.AUTOMATION_RUN_FAILED,
|
||||
subject_id=automation.id,
|
||||
data={'name': automation.name, 'error': error},
|
||||
)
|
||||
|
||||
|
||||
####################
|
||||
|
||||
Reference in new issue
Block a user