Option to manually run tasks

This commit is contained in:
Georges-Antoine Assi
2023-12-04 13:40:33 -05:00
parent 79dd36d98d
commit 1e72672b20
7 changed files with 47 additions and 7 deletions

View File

@@ -0,0 +1,15 @@
from fastapi import APIRouter, Request
from utils.oauth import protected_route
from tasks.update_mame_xml import update_mame_xml_task
from tasks.update_switch_titledb import update_switch_titledb_task
router = APIRouter()
@protected_route(router.post, "/tasks/run", ["tasks.run"])
async def run_tasks(request: Request):
"""Run all async tasks"""
await update_mame_xml_task.run()
await update_switch_titledb_task.run()
return {"message": "All tasks run successfully!"}

View File

@@ -13,7 +13,7 @@ def test_heartbeat():
"WATCHER": {
"ENABLED": True,
"TITLE": "Rescan on filesystem change",
"MESSAGE": "Runs a scan when a change is detected in the library path, with a 5 minutes delay",
"MESSAGE": "Runs a scan when a change is detected in the library path, with a 5 minute delay",
},
"SCHEDULER": {
"RESCAN": {
@@ -32,7 +32,7 @@ def test_heartbeat():
"ENABLED": True,
"CRON": "0 5 * * *",
"TITLE": "Scheduled MAME XML update",
"MESSAGE": "Updates the Nintedo MAME XML file",
"MESSAGE": "Updates the MAME XML file",
},
},
}

View File

@@ -22,7 +22,7 @@ from config import (
ENABLE_SCHEDULED_UPDATE_MAME_XML,
SCHEDULED_UPDATE_MAME_XML_CRON,
)
from endpoints import search, platform, rom, identity, oauth, scan # noqa
from endpoints import search, platform, rom, identity, oauth, scan, tasks # noqa
from handler import dbh
from utils.socket import socket_app
from utils.auth import (
@@ -68,6 +68,7 @@ app.include_router(identity.router)
app.include_router(platform.router)
app.include_router(rom.router)
app.include_router(search.router)
app.include_router(tasks.router)
add_pagination(app)
app.mount("/ws", socket_app)
@@ -81,7 +82,7 @@ def heartbeat():
"WATCHER": {
"ENABLED": ENABLE_RESCAN_ON_FILESYSTEM_CHANGE,
"TITLE": "Rescan on filesystem change",
"MESSAGE": f"Runs a scan when a change is detected in the library path, with a {RESCAN_ON_FILESYSTEM_CHANGE_DELAY} minutes delay",
"MESSAGE": f"Runs a scan when a change is detected in the library path, with a {RESCAN_ON_FILESYSTEM_CHANGE_DELAY} minute delay",
},
"SCHEDULER": {
"RESCAN": {
@@ -100,7 +101,7 @@ def heartbeat():
"ENABLED": ENABLE_SCHEDULED_UPDATE_MAME_XML,
"CRON": SCHEDULED_UPDATE_MAME_XML_CRON,
"TITLE": "Scheduled MAME XML update",
"MESSAGE": "Updates the Nintedo MAME XML file",
"MESSAGE": "Updates the MAME XML file",
},
},
}

View File

@@ -20,7 +20,7 @@ class UpdateMAMEXMLTask(RemoteFilePullTask):
description="mame xml update",
enabled=ENABLE_SCHEDULED_UPDATE_MAME_XML,
cron_string=SCHEDULED_UPDATE_MAME_XML_CRON,
url="https://hyperlist.hyperspin-fe.com/genall.php?system=6",
url="https://gist.githubusercontent.com/gantoine/0e2b9e25962bfd661ad2fe0ba0e72766/raw/59133cc98fa4c58992e4a789db394a85953b24df/gistfile1.txt",
file_path=FIXTURE_FILE_PATH,
)

View File

@@ -28,6 +28,7 @@ WRITE_SCOPES_MAP: Final = {
FULL_SCOPES_MAP: Final = {
"users.read": "View users",
"users.write": "Modify users",
"tasks.run": "Run tasks",
}
DEFAULT_SCOPES: Final = list(DEFAULT_SCOPES_MAP.keys())

View File

@@ -1,5 +1,5 @@
<script setup>
import { ref, onBeforeMount } from "vue";
import { ref, onBeforeMount, inject } from "vue";
import { api } from "@/services/api";
import TaskWatcher from "@/components/Settings/General/TaskStatus/TaskWatcher.vue";
import TaskScheduler from "@/components/Settings/General/TaskStatus/TaskScheduler.vue";
@@ -7,6 +7,25 @@ import TaskScheduler from "@/components/Settings/General/TaskStatus/TaskSchedule
// Props
const watcher = ref({});
const scheduler = ref({});
const emitter = inject("emitter");
// Methods
const runAllTasks = async () => {
const result = await api.post("/tasks/run");
if (result.status !== 200) {
return emitter.emit("snackbarShow", {
msg: "Error running tasks",
icon: "mdi-close-circle",
color: "red",
});
}
emitter.emit("snackbarShow", {
msg: result.data.message,
icon: "mdi-check-circle",
color: "green",
});
};
onBeforeMount(async () => {
const { data } = await api.get("/heartbeat");
@@ -21,6 +40,9 @@ onBeforeMount(async () => {
<v-icon class="mr-3">mdi-pulse</v-icon>
Task Status
</v-toolbar-title>
<v-toolbar-items>
<v-btn @click="runAllTasks"> Run all </v-btn>
</v-toolbar-items>
</v-toolbar>
<v-divider class="border-opacity-25" />

View File

@@ -9,6 +9,7 @@ const FULL_SCOPES_LIST = [
"platforms.write",
"users.read",
"users.write",
"tasks.run",
];
export default defineStore("auth", {