LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
Enable ETL prerun checks (#444)
Athul9d63850acce9
diff --git a/backend/account/subscription_loader.py b/backend/account/subscription_loader.pyindex d380ed19d..133a4d9eb 100644--- a/backend/account/subscription_loader.py+++ b/backend/account/subscription_loader.py@@ -4,6 +4,7 @@ from importlib import import_modulefrom typing import Anyfrom django.apps import apps+from django.utils import timezonelogger = logging.getLogger(__name__)@@ -75,3 +76,32 @@ def load_plugins() -> list[Any]:logger.info("No subscription plugins found.")return subscription_plugins+++def validate_etl_run(org_id: str) -> bool:+ """Method to check subscription status before ETL runs.++ Args:+ org_id: The ID of the organization.++ Returns:+ A boolean indicating whether the pre-run check passed or not.+ """+ try:+ from pluggable_apps.subscription.subscription_helper import SubscriptionHelper+ except ModuleNotFoundError:+ logger.error("Subscription plugin not found.")+ return False++ org_plans = SubscriptionHelper.get_subscription(org_id)+ if not org_plans or not org_plans.is_active:+ return False++ if org_plans.is_paid:+ return True++ if timezone.now() >= org_plans.end_date:+ logger.debug(f"Trial expired for org {org_id}")+ return False++ return Truediff --git a/backend/scheduler/tasks.py b/backend/scheduler/tasks.pyindex e03dc3b28..dbc6f6101 100644--- a/backend/scheduler/tasks.py+++ b/backend/scheduler/tasks.py@@ -3,6 +3,7 @@ import loggingfrom typing import Anyfrom account.models import Organization+from account.subscription_loader import load_plugins, validate_etl_runfrom celery import shared_taskfrom django_celery_beat.models import CrontabSchedule, PeriodicTaskfrom django_tenants.utils import get_tenant_model, tenant_context@@ -12,6 +13,7 @@ from workflow_manager.workflow.models.workflow import Workflowfrom workflow_manager.workflow.workflow_helper import WorkflowHelperlogger = logging.getLogger(__name__)+subscription_loader = load_plugins()def create_periodic_task(@@ -57,13 +59,25 @@ def execute_pipeline_task(name: Any,) -> None:logger.info(f"Executing pipeline name: {name}")-try:logger.info(f"Executing workflow id: {workflow_id}")tenant: Organization = (get_tenant_model().objects.filter(schema_name=org_schema).first())with tenant_context(tenant):+ if (+ subscription_loader+ and subscription_loader[0]+ and not validate_etl_run(org_schema)+ ):+ try:+ logger.info(f"Disabling ETL task: {pipepline_id}")+ disable_task(pipepline_id)+ except Exception as e:+ logger.warning(+ f"Failed to disable task: {pipepline_id}. Error: {e}"+ )+ returnworkflow = Workflow.objects.get(id=workflow_id)logger.info(f"Executing workflow: {workflow}")PipelineProcessor.update_pipeline(@@ -88,7 +102,6 @@ def delete_periodic_task(task_name: str) -> None:logger.error(f"Periodic task does not exist: {task_name}")-@shared_taskdef disable_task(task_name: str) -> None:task = PeriodicTask.objects.get(name=task_name)task.enabled = False@@ -96,7 +109,6 @@ def disable_task(task_name: str) -> None:PipelineProcessor.update_pipeline(task_name, Pipeline.PipelineStatus.PAUSED, False)-@shared_taskdef enable_task(task_name: str) -> None:task = PeriodicTask.objects.get(name=task_name)task.enabled = True