Skip to main content

CleanupInterceptor automatically cleans up temporary artifacts and activity state when workflows complete or fail. Supports multiple cleanup base paths and comprehensive error handling. Cleanup runs automatically after workflow completion or failure, supports multiple cleanup paths, and cleanup failures are logged but don't fail workflows.

CleanupInterceptor is part of the Interceptors system and can be combined with other interceptors.

CleanupInterceptor

Class
📁application_sdk.interceptors.cleanup

Automatically cleans up temporary artifacts and activity state when workflows complete or fail. Supports multiple cleanup base paths and comprehensive error handling. Cleanup runs automatically after workflow completion or failure, supports multiple cleanup paths, and cleanup failures are logged but don't fail workflows.

Methods1

__init__

__init__(self)
Initialize CleanupInterceptor. No parameters required.

Usage Examples

Register CleanupInterceptor with worker

Register CleanupInterceptor to automatically clean up temporary artifacts after workflow execution

from application_sdk.interceptors import CleanupInterceptor
from temporalio.worker import Worker

worker = Worker(
client,
task_queue="my-task-queue",
workflows=[MyWorkflow],
activities=[my_activity, cleanup],
interceptors=[CleanupInterceptor()]
)

Cleanup paths

The interceptor cleans up paths following this pattern:

{base_path}/{app_name}/{workflow_id}/{run_id}

Default path: Uses TEMPORARY_PATH with workflow-specific output path.

Configured paths: Can specify multiple paths via ATLAN_CLEANUP_BASE_PATHS environment variable (comma-separated).

Single cleanup path:

ATLAN_CLEANUP_BASE_PATHS="./local/tmp/artifacts/apps"

Multiple cleanup paths:

ATLAN_CLEANUP_BASE_PATHS="./local/tmp/artifacts/apps,/storage/temp/apps,/shared/cleanup/apps"

Cleanup behavior

  • Removes entire directory and recreates it empty
  • Handles both existing and non-existing directories
  • Individual path failures don't stop cleanup of other paths
  • All errors are logged with context
  • Uses Temporal retry policy with maximum 3 attempts and 5-minute timeout

See also