Run background job from API endpoint
This commit is contained in:
parent
aeb5abad41
commit
e434d28c16
@ -21,7 +21,7 @@ Store all the logs for the current job in order to be able to debug and keep tra
|
||||
- [x] Be able to move and rename files based on a regex
|
||||
- [x] Read qbittorrent credentials from .env file
|
||||
- [x] Implement API endpoint using FastAPI
|
||||
- [ ] Run organization ob on a separate thread
|
||||
- [x] Run organization job on a separate thread
|
||||
- [ ] Deduplicate files using Czkawka
|
||||
- [ ] Add unit tests
|
||||
- [ ] Add logging
|
||||
|
||||
17
src/main.py
17
src/main.py
@ -1,10 +1,11 @@
|
||||
import os
|
||||
from fastapi import FastAPI
|
||||
from fastapi import BackgroundTasks, FastAPI
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from qbittorrent_api import get_qbittorrent_files_downloading
|
||||
from filemoving import group_files_by_prefix
|
||||
import uuid
|
||||
import time
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@ -19,11 +20,17 @@ if not qbit_url or not qbit_user or not qbit_password or not target_dir:
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
def root(background_tasks: BackgroundTasks):
|
||||
job_id = str(uuid.uuid4())
|
||||
background_tasks.add_task(launch_job, job_id)
|
||||
return job_id
|
||||
|
||||
def launch_job(job_id):
|
||||
# WARNING: Temporary code for testing purposes
|
||||
time.sleep(5)
|
||||
|
||||
with open("jobs.txt", "a") as f:
|
||||
f.write(f"{job_id}\n")
|
||||
|
||||
# TODO Launch the job in the background
|
||||
# downloading = get_qbittorrent_files_downloading(qbit_url, qbit_user, qbit_password)
|
||||
# group_files_by_prefix(target_dir, downloading)
|
||||
|
||||
return job_id
|
||||
|
||||
Loading…
Reference in New Issue
Block a user