Compare commits

..

2 Commits

Author SHA1 Message Date
Ventilaar
5a4726ac10 Add queue download function
All checks were successful
Update worker server / build-and-publish (release) Successful in 9s
Generate docker image / build-and-publish (release) Successful in 1m3s
2025-01-18 22:20:17 +01:00
Ventilaar
46bde82d32 Hotfix shared state issue
All checks were successful
Update worker server / build-and-publish (release) Successful in 12s
Generate docker image / build-and-publish (release) Successful in 19s
2024-12-07 14:58:52 +01:00
5 changed files with 34 additions and 7 deletions

View File

@@ -4,4 +4,4 @@ COPY requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "ayta:create_app()"]
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "1", "ayta:create_app()"]

View File

@@ -2,7 +2,7 @@ from flask import Blueprint, render_template, request, redirect, url_for, flash,
from ..nosql import get_nosql
from ..dlp import checkChannelId, getChannelInfo
from ..decorators import login_required
from ..tasks import test_sleep, websub_subscribe_callback, websub_unsubscribe_callback, video_download
from ..tasks import test_sleep, websub_subscribe_callback, websub_unsubscribe_callback, video_download, video_queue
from datetime import datetime
from secrets import token_urlsafe
@@ -251,6 +251,8 @@ def workers():
task = request.form.get('task', None)
if task == 'test-sleep':
test_sleep.delay()
elif task == 'queue-single':
video_queue.delay()
celery = current_app.extensions.get('celery')

View File

@@ -429,7 +429,15 @@ class Mango:
def queue_emptyQueue(self):
return self.download_queue.delete_many({})
def queue_getNext(self, newest=False):
sort = []
if newest:
sort = [( 'created_time', pymongo.DESCENDING )]
return self.download_queue.find_one({}, sort=sort)
##########################################
# HELPER FUNCTIONS #
##########################################
@@ -453,7 +461,4 @@ def clean_info_json(originalInfo, format='dict'):
return json.dumps(originalInfo)
else:
print('The requested output format is not supported!')
if __name__ == '__main__':
mango = Mango('mongodb://root:example@192.168.66.140:27017')

View File

@@ -24,6 +24,25 @@ def video_download(videoId):
return False
return True
@shared_task()
def video_queue():
"""
Gets the oldest video ID from the queue and runs video_download() on it.
"""
from .nosql import get_nosql
videoId = get_nosql().queue_getNext()
if videoId:
videoId = videoId['id']
else:
return None
if video_download(videoId):
get_nosql().queue_deleteQueue(videoId)
return True
else:
return False
@shared_task()
def websub_subscribe_callback(channelId):

View File

@@ -16,6 +16,7 @@
</div>
<form method="POST">
<input title="test-sleep" type="submit" value="test-sleep" name="task">
<input title="test-sleep" type="submit" value="queue-single" name="task">
</form>
<div class="divider"></div>
<div class="row">