Files
matitos_news/app_urls/api/views.py
2025-03-18 17:38:01 +01:00

20 lines
945 B
Python

import django_rq
from django.http import JsonResponse
from .tasks import background_task
import os
from .src.logger import get_logger
logger = get_logger()
# TODO: Queues with priorities, process_raw_urls, process_error_urls least priority due to slowdown logic
def trigger_task(request, task):
"""View that enqueues a task."""
queue = django_rq.get_queue('default') # Get the default queue
job = queue.enqueue(background_task, task)
return JsonResponse({"message": "Task has been enqueued!", "job_id": job.id})
def link_list(request):
prefix = "http://localhost:8000/api"
links = ["fetch_feeds", "fetch_parser", "process_raw_urls", "process_error_urls", "process_missing_kids_urls_50", "process_missing_kids_urls_500000"]
return JsonResponse({"links": ["http://localhost:8080/?pgsql=matitos_db&username=supermatitos&db=matitos&ns=public&select=urls&order%5B0%5D=id"] + [os.path.join(prefix, l) for l in links]})