Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 699ce51

Browse files
authored
Merge pull request #16 from bemble/fix_worker
catch worker exceptions
2 parents 4381805 + 8c01570 commit 699ce51

File tree

8 files changed

+35
-1
lines changed

8 files changed

+35
-1
lines changed

front/src/i18n/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"title": "Status",
6767
"websocket": "Websocket",
6868
"app_version": "Application version: ",
69+
"worker_last_run": "Worker last run",
6970
"debrider": "Debrider",
7071
"downloader": "Downloader",
7172
"restart": "Restart",

front/src/i18n/fr.json

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"title": "États",
6666
"websocket": "Websocket",
6767
"app_version": "Version de l'application : ",
68+
"worker_last_run": "Dernière exécution du worker :",
6869
"debrider": "Débrideur",
6970
"downloader": "Téléchargeur",
7071
"restart": "Redémarrer",

front/src/models/status.type.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
export type Status = {
22
app: {
33
version: string;
4+
worker: {
5+
last_run: string;
6+
};
47
};
58
debrider: {
69
id: string;

front/src/pages/Status/Status.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ const Status = () => {
5252
{isLoading ? t("loading") : status?.app.version}
5353
</code>
5454
</div>
55+
<div>
56+
{t("status.worker_last_run")}{" "}
57+
<code
58+
className={classNames(classes.code, {
59+
[classes.pending]: isLoading,
60+
})}
61+
>
62+
{isLoading
63+
? t("loading")
64+
: new Date(
65+
status?.app.worker.last_run as any
66+
).toLocaleString()}
67+
</code>
68+
</div>
5569
<div className={classes.spacer} />
5670
<hr className={classes.separator} />
5771
<div className={classes.spacer} />

server/holerr/api/routers/routers_models.py

+4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ class StatusElement(BaseModel):
7878
name: str
7979
connected: bool
8080

81+
class WorkerElement(BaseModel):
82+
last_run: datetime | None
83+
8184
class StatusApp(BaseModel):
8285
version: str
86+
worker: WorkerElement
8387

8488
class Status(BaseModel):
8589
app: StatusApp

server/holerr/api/routers/status.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from holerr.downloaders import downloader
33
from .routers_models import Status
44
from holerr.utils import info
5+
from holerr.tasks import worker
56

67
from fastapi import APIRouter
78

@@ -13,6 +14,9 @@ async def get_status():
1314
return {
1415
"app": {
1516
"version": info.get_app_version(),
17+
"worker": {
18+
"last_run": worker.last_run,
19+
}
1620
},
1721
"debrider": {
1822
"id": debrider.get_id(),

server/holerr/tasks/worker.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
import asyncio
55
import threading
6+
from datetime import datetime
67

78
log = Log.get_logger(__name__)
89

910

1011
class Worker:
1112
_worker: threading.Thread = None
1213
_tasks: list[Task] = []
14+
last_run: datetime = None
1315

1416
def add(self, task: Task):
1517
log.debug(type(task).__name__ + " added")
@@ -35,5 +37,9 @@ async def _run(self):
3537
log.debug("Starting workers")
3638
while True:
3739
for task in self._tasks:
38-
await task.run()
40+
try:
41+
await task.run()
42+
except Exception as e:
43+
log.error(f"Error while running task, {e}")
44+
self.last_run = datetime.now()
3945
await asyncio.sleep(5)

server/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SQLAlchemy==2.0.29
2525
starlette==0.37.2
2626
torf==4.2.6
2727
typing_extensions==4.11.0
28+
tzdata==2024.1
2829
urllib3==2.2.1
2930
uvicorn==0.29.0
3031
uvloop==0.19.0

0 commit comments

Comments
 (0)