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 = []