45 lines
2.0 KiB
Python
45 lines
2.0 KiB
Python
from django.core.management.base import BaseCommand
|
|
from api.organization.models import Organizacion
|
|
from api.customs.tasks import microservice_v2
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Ejecuta tareas de microservicio por organización y procesamiento.'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'--organizacion_id',
|
|
type=str,
|
|
help='ID de la organización a procesar (opcional, si no se envía se procesan todas)'
|
|
)
|
|
parser.add_argument(
|
|
'--procesamiento',
|
|
type=str,
|
|
help='Tipo de procesamiento a ejecutar (opcional, si no se envía se ejecutan todos)'
|
|
)
|
|
parser.add_argument(
|
|
'--todos',
|
|
type=bool,
|
|
help='Ejecutar todos los procesos (opcional)'
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
todos = options.get('todos', False)
|
|
organizacion_id = options.get('organizacion_id')
|
|
procesamiento = options.get('procesamiento')
|
|
if todos:
|
|
organizaciones = Organizacion.objects.all()
|
|
for org in organizaciones:
|
|
microservice_v2.ejecutar_todos_por_organizacion(org.id)
|
|
self.stdout.write(self.style.SUCCESS('Se ejecutaron todos los procesos para todas las organizaciones.'))
|
|
return
|
|
|
|
if organizacion_id:
|
|
if procesamiento:
|
|
# microservice_v2.ejecutar_procesamiento_por_organizacion(organizacion_id, procesamiento)
|
|
microservice_v2.ejecutar_por_organizacion_y_procesamiento(organizacion_id, procesamiento)
|
|
self.stdout.write(self.style.SUCCESS(f'Se ejecutó el procesamiento {procesamiento} para la organización {organizacion_id}.'))
|
|
else:
|
|
microservice_v2.ejecutar_todos_por_organizacion(organizacion_id)
|
|
self.stdout.write(self.style.SUCCESS(f'Se ejecutaron todos los procesos para la organización {organizacion_id}.'))
|
|
|