From e2d3868a9ecfb3ddef3799aa2f181b6d22dcd76f Mon Sep 17 00:00:00 2001 From: pi-ux-ce Date: Thu, 8 Jan 2026 23:31:22 +0000 Subject: [PATCH] add prowlarr script in tash until I create a prowlarr project with celery --- django_code/stash_management/apps.py | 42 +++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/django_code/stash_management/apps.py b/django_code/stash_management/apps.py index 74d430d..88f91ba 100644 --- a/django_code/stash_management/apps.py +++ b/django_code/stash_management/apps.py @@ -4,7 +4,7 @@ from django.shortcuts import render from django.shortcuts import redirect from django.core.files import File from kubernetes import client, config -from celery import shared_task +from celery import shared_task,group from lxml import html import requests @@ -18,8 +18,15 @@ import yaml from urllib import request as urlrequest from urllib import parse as urlparse +BASE_URL="https://prowlarr.tryton.geeraert.eu" +API_KEY="c5655e0b915d46dbb68d80f40a2daae4" +APP_PROFILE_ID = 1 # The ID you want to inject +headers = { + "accept": "application/json", + "X-Api-Key": API_KEY +} proxy_url = 'http://gluetun-svc.gluetun.svc:8888' @@ -272,4 +279,37 @@ def handle_survey_form(request): +@shared_task(bind=True, max_retries=3, rate_limit='10/s') +def process_indexer_task(self, indexer, app_profile_id): + """Processes a single indexer POST request.""" + indexer['appProfileId'] = app_profile_id + headers = {"accept": "application/json", "X-Api-Key": API_KEY} + + try: + response = requests.post(f"{BASE_URL}/api/v1/indexer", headers=headers, json=indexer) + response.raise_for_status() + return f"Successfully added {indexer.get('name')}" + except requests.exceptions.RequestException as exc: + # Retry individual failure without affecting other 599 tasks + raise self.retry(exc=exc, countdown=60) + +@shared_task +def run_bulk_indexer_import(app_profile_id=1): + """Orchestrates the bulk import of all available indexers.""" + headers = {"accept": "application/json", "X-Api-Key": API_KEY} + response = requests.get(f"{BASE_URL}/api/v1/indexer/schema", headers=headers) + + if response.status_code == 200: + available_indexers = response.json() + + # Create a group of individual tasks + job = group( + process_indexer_task.s(indexer, app_profile_id) + for indexer in available_indexers + ) + job.apply_async() + + + +