SIENTIAPDE-1350: Implement file cleanup workflow and activities, including MinIO and local directory cleanup, configuration, and metrics.
This commit is contained in:
76
scripts/run_cleanup_test.py
Normal file
76
scripts/run_cleanup_test.py
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run cleanup_files workflow once for manual testing.
|
||||
|
||||
This script starts the Temporal workflow `cleanup_files` a single time,
|
||||
using the same Temporal namespace and task queue as the main worker.
|
||||
|
||||
It is intended only for local/manual testing; scheduling (cron) must be
|
||||
configured separately in Temporal.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import sys
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
from temporalio.client import Client
|
||||
|
||||
# Ensure project root is on PYTHONPATH when running directly
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if ROOT_DIR not in sys.path:
|
||||
sys.path.insert(0, ROOT_DIR)
|
||||
|
||||
from model_manager.workflows.cleanup_files import CleanupFiles # noqa: E402
|
||||
|
||||
|
||||
async def main(argv: list[str]) -> None:
|
||||
"""Entry point for manual cleanup workflow execution.
|
||||
|
||||
Args:
|
||||
argv: Command-line arguments (excluding program name).
|
||||
"""
|
||||
|
||||
# Config from environment / defaults
|
||||
temporal_host = os.getenv('TEMPORAL_HOST', 'localhost:37463')
|
||||
temporal_namespace = os.getenv('TEMPORAL_NAMESPACE', 'model-manager')
|
||||
task_queue = 'cleanup-queue'
|
||||
|
||||
default_bucket = os.getenv('DEFAULT_CLEANUP_BUCKET', 'model-training')
|
||||
|
||||
# Optional CLI: bucket name override
|
||||
bucket_name = default_bucket
|
||||
if argv:
|
||||
bucket_name = argv[0]
|
||||
|
||||
print(f"Connecting to Temporal at {temporal_host} (namespace={temporal_namespace})...")
|
||||
client = await Client.connect(temporal_host, namespace=temporal_namespace)
|
||||
|
||||
input_data: dict[str, Any] = {
|
||||
'bucket_name': bucket_name,
|
||||
}
|
||||
|
||||
workflow_id = f"cleanup-files-manual-{int(asyncio.get_event_loop().time())}"
|
||||
|
||||
print(f"Starting cleanup_files workflow once...\n"
|
||||
f" workflow_id = {workflow_id}\n"
|
||||
f" task_queue = {task_queue}\n"
|
||||
f" bucket_name = {bucket_name}")
|
||||
|
||||
handle = await client.start_workflow(
|
||||
CleanupFiles.run,
|
||||
input_data,
|
||||
id=workflow_id,
|
||||
task_queue=task_queue,
|
||||
run_timeout=timedelta(minutes=10),
|
||||
)
|
||||
|
||||
print("Workflow started, waiting for completion...")
|
||||
await handle.result()
|
||||
print("cleanup_files workflow completed successfully.")
|
||||
|
||||
|
||||
if __name__ == '__main__': # pragma: no cover - manual utility script
|
||||
asyncio.run(main(sys.argv[1:]))
|
||||
Reference in New Issue
Block a user