Improve job id. Fix refreshing list of jobs on delete from config page

This commit is contained in:
Debanjum Singh Solanky
2024-04-26 18:08:57 +05:30
parent a1e5195c8b
commit 7e084ef1e0
2 changed files with 7 additions and 4 deletions

View File

@@ -661,8 +661,6 @@
function deleteTask(taskId) { function deleteTask(taskId) {
const scheduledTaskList = document.getElementById("scheduled-tasks-list"); const scheduledTaskList = document.getElementById("scheduled-tasks-list");
// url encode the task id
taskId = encodeURIComponent(taskId);
fetch(`/api/task?task_id=${taskId}`, { fetch(`/api/task?task_id=${taskId}`, {
method: 'DELETE', method: 'DELETE',
}) })

View File

@@ -1,4 +1,5 @@
import functools import functools
import hashlib
import json import json
import logging import logging
import math import math
@@ -400,6 +401,8 @@ async def websocket_endpoint(
except ValueError as e: except ValueError as e:
await send_complete_llm_response(f"Unable to create reminder with crontime schedule: {crontime}") await send_complete_llm_response(f"Unable to create reminder with crontime schedule: {crontime}")
continue continue
# Generate the job id from the hash of inferred_query and crontime
job_id = hashlib.md5(f"{inferred_query}_{crontime}".encode("utf-8")).hexdigest()
partial_scheduled_chat = functools.partial( partial_scheduled_chat = functools.partial(
scheduled_chat, inferred_query, websocket.user.object, websocket.url scheduled_chat, inferred_query, websocket.user.object, websocket.url
) )
@@ -411,7 +414,7 @@ async def websocket_endpoint(
partial_scheduled_chat, partial_scheduled_chat,
f"{ProcessLock.Operation.SCHEDULED_JOB}_{user.uuid}_{inferred_query}", f"{ProcessLock.Operation.SCHEDULED_JOB}_{user.uuid}_{inferred_query}",
), ),
id=f"job_{user.uuid}_{inferred_query}_{crontime}", id=f"job_{user.uuid}_{job_id}",
name=f"{inferred_query}", name=f"{inferred_query}",
max_instances=2, # Allow second instance to kill any previous instance with stale lock max_instances=2, # Allow second instance to kill any previous instance with stale lock
jitter=30, jitter=30,
@@ -663,13 +666,15 @@ async def chat(
status_code=500, status_code=500,
) )
# Generate the job id from the hash of inferred_query and crontime
job_id = hashlib.md5(f"{inferred_query}_{crontime}".encode("utf-8")).hexdigest()
partial_scheduled_chat = functools.partial(scheduled_chat, inferred_query, request.user.object, request.url) partial_scheduled_chat = functools.partial(scheduled_chat, inferred_query, request.user.object, request.url)
try: try:
job = state.scheduler.add_job( job = state.scheduler.add_job(
run_with_process_lock, run_with_process_lock,
trigger=trigger, trigger=trigger,
args=(partial_scheduled_chat, f"{ProcessLock.Operation.SCHEDULED_JOB}_{user.uuid}_{inferred_query}"), args=(partial_scheduled_chat, f"{ProcessLock.Operation.SCHEDULED_JOB}_{user.uuid}_{inferred_query}"),
id=f"job_{user.uuid}_{inferred_query}_{crontime}", id=f"job_{user.uuid}_{job_id}",
name=f"{inferred_query}", name=f"{inferred_query}",
max_instances=2, # Allow second instance to kill any previous instance with stale lock max_instances=2, # Allow second instance to kill any previous instance with stale lock
jitter=30, jitter=30,