From eeeabca8c290041f0f3cfc94c69f8d136420cfba Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 7 Jun 2022 17:09:49 +0700 Subject: [PATCH 1/4] bump dependencies --- tubearchivist/requirements.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tubearchivist/requirements.txt b/tubearchivist/requirements.txt index a1e49c9..1c686d3 100644 --- a/tubearchivist/requirements.txt +++ b/tubearchivist/requirements.txt @@ -1,12 +1,12 @@ beautifulsoup4==4.11.1 celery==5.2.7 -Django==4.0.4 -django-cors-headers==3.12.0 +Django==4.0.5 +django-cors-headers==3.13.0 djangorestframework==3.13.1 Pillow==9.1.1 -redis==4.3.1 +redis==4.3.3 requests==2.27.1 ryd-client==0.0.3 uWSGI==2.0.20 -whitenoise==6.1.0 +whitenoise==6.2.0 yt_dlp==2022.5.18 From 4d9ee4494f9da6eab223e771cc5d7fa18f4ed703 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 14 Jun 2022 14:26:49 +0700 Subject: [PATCH 2/4] bump requests --- tubearchivist/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubearchivist/requirements.txt b/tubearchivist/requirements.txt index 1c686d3..3fe0767 100644 --- a/tubearchivist/requirements.txt +++ b/tubearchivist/requirements.txt @@ -5,7 +5,7 @@ django-cors-headers==3.13.0 djangorestframework==3.13.1 Pillow==9.1.1 redis==4.3.3 -requests==2.27.1 +requests==2.28.0 ryd-client==0.0.3 uWSGI==2.0.20 whitenoise==6.2.0 From bbb16bb3c2fb902e7b5ad8b7d5e015736bc8b2be Mon Sep 17 00:00:00 2001 From: lamusmaser <1940060+lamusmaser@users.noreply.github.com> Date: Tue, 14 Jun 2022 20:15:59 -0600 Subject: [PATCH 3/4] Update TaskAPIView with GET - #257 PR (#258) * Initial commit for GET response for TaskAPIView. * Update for missing space - linting issue. * Additional linting fixes. * add is_locked method to check if lock is set * Update to use `.is_locked` method and add decorator. * Fix linting issue. * Fix doubled "rescan" call for locked file. Removed call to ".owned()" under "is_locked". * Commenting out GET call in TaskAPI view to revert change for testing. * Commenting is_locked function to see if Server Response 500 is stopped. * Reassert is_locked function within RedisArchivist class. * Create test GET responder. * Reverting simple GET response change. * Reapplying simple GET response for `/api/task/`. * Reapplying change with modification to lock key. * Documentation update for new GET calls. * README: fix returned value as `bool` instead of `str`. * Updating the `is_locked` key reference to "rescan" and "downloading" to fix which key is being retrieved. * Use dictionary keys, rather than line-by-line statements. * Fix typo in README for Task View. Co-authored-by: simon --- tubearchivist/api/README.md | 14 ++++++++++++++ tubearchivist/api/views.py | 11 +++++++++++ tubearchivist/home/src/ta/ta_redis.py | 6 ++++++ 3 files changed, 31 insertions(+) diff --git a/tubearchivist/api/README.md b/tubearchivist/api/README.md index c0889d3..0316b3e 100644 --- a/tubearchivist/api/README.md +++ b/tubearchivist/api/README.md @@ -202,6 +202,20 @@ When valid returns message with user id: ``` ## Task View +GET /api/task/ +POST /api/task/ + +Check if there is an ongoing task: +GET /api/task/ + +Returns: +```json +{ + "rescan": false, + "downloading": false +} +``` + Start a background task POST /api/task/ ```json diff --git a/tubearchivist/api/views.py b/tubearchivist/api/views.py index d1165c2..f695fab 100644 --- a/tubearchivist/api/views.py +++ b/tubearchivist/api/views.py @@ -452,9 +452,20 @@ class LoginApiView(ObtainAuthToken): class TaskApiView(ApiBaseView): """resolves to /api/task/ + GET: check if ongoing background task POST: start a new background task """ + @staticmethod + def get(request): + """handle get request""" + + response = {"rescan": False, "downloading": False} + for key in response.keys(): + response[key] = RedisArchivist().is_locked(key) + + return Response(response) + def post(self, request): """handle post request""" diff --git a/tubearchivist/home/src/ta/ta_redis.py b/tubearchivist/home/src/ta/ta_redis.py index e13a997..43e9ab6 100644 --- a/tubearchivist/home/src/ta/ta_redis.py +++ b/tubearchivist/home/src/ta/ta_redis.py @@ -80,6 +80,12 @@ class RedisArchivist(RedisBase): redis_lock = self.conn.lock(self.NAME_SPACE + lock_key) return redis_lock + def is_locked(self, lock_key): + """check if lock is set""" + lock_name = self.NAME_SPACE + lock_key + lock_status = bool(self.conn.execute_command("GET", lock_name)) + return lock_status + def get_progress(self): """get a list of all progress messages""" all_messages = [] From 83a90000c6be6008e60db201e9207a7c62edd71d Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 15 Jun 2022 09:23:41 +0700 Subject: [PATCH 4/4] bump base image --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2651f86..19efc8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ # First stage to build python wheel -FROM python:3.10.4-slim-bullseye AS builder +FROM python:3.10.5-slim-bullseye AS builder ARG TARGETPLATFORM RUN apt-get update @@ -14,7 +14,7 @@ COPY ./tubearchivist/requirements.txt /requirements.txt RUN pip install --user -r requirements.txt # build final image -FROM python:3.10.4-slim-bullseye as tubearchivist +FROM python:3.10.5-slim-bullseye as tubearchivist ARG TARGETPLATFORM ARG INSTALL_DEBUG