Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.6 KB
Raw Blame
"""Infrastructure adapters used by the workflow-run archive application service."""

from libs.archive_storage import get_export_storage
from services.retention.workflow_run.archive_download_task import WorkflowRunArchiveDownloadTask

_ARCHIVE_DOWNLOAD_MIME_TYPE = "application/zip"


def dispatch_workflow_run_archive_deletion_task(*, tenant_id: str, year: int, month: int) -> None:
    """Enqueue an archive-only deletion whose durable request is already committed."""
    from tasks.workflow_run_archive_deletion_tasks import delete_workflow_run_archive_task

    delete_workflow_run_archive_task.apply_async(args=(tenant_id, year, month))


def dispatch_workflow_run_archive_download_task(
    task: WorkflowRunArchiveDownloadTask,
) -> None:
    """Enqueue ZIP preparation after the application service claims the Celery task id."""
    from tasks.workflow_run_archive_download_tasks import prepare_workflow_run_archive_download_task

    celery_task_id = task.celery_task_id
    if celery_task_id is None:
        raise ValueError("celery_task_id is required before dispatch")

    prepare_workflow_run_archive_download_task.apply_async(
        args=(task.tenant_id, task.download_id),
        task_id=celery_task_id,
    )


def sign_workflow_run_archive_download_url(
    storage_key: str,
    *,
    expires_in: int,
    filename: str,
) -> str:
    """Create a browser download URL without initializing export storage during app startup."""
    return get_export_storage().generate_presigned_url(
        storage_key,
        expires_in=expires_in,
        filename=filename,
        content_type=_ARCHIVE_DOWNLOAD_MIME_TYPE,
    )