|
31 | 31 | from typing import List, Dict, Tuple, Type |
32 | 32 | import urllib.parse |
33 | 33 |
|
34 | | -import aiofiles |
35 | 34 | import redis # type: ignore |
36 | 35 | import redis.asyncio # type: ignore |
37 | 36 | import pydantic |
@@ -1381,28 +1380,35 @@ def execute(self, context: JobExecutionContext, |
1381 | 1380 | async def migrate_logs(redis_url: str, redis_key: str, file_name: str): |
1382 | 1381 | ''' Uploads logs to S3 and deletes them from Redis. Returns the S3 file path. ''' |
1383 | 1382 |
|
1384 | | - async with aiofiles.tempfile.NamedTemporaryFile(mode='w+') as temp_file: |
| 1383 | + fd, tmp_path = tempfile.mkstemp(suffix='.log') |
| 1384 | + try: |
| 1385 | + os.close(fd) |
| 1386 | + |
1385 | 1387 | await connectors.write_redis_log_to_disk( |
1386 | 1388 | redis_url, |
1387 | 1389 | redis_key, |
1388 | | - str(temp_file.name), |
| 1390 | + tmp_path, |
1389 | 1391 | ) |
1390 | 1392 |
|
1391 | 1393 | await progress_writer.report_progress_async() |
1392 | 1394 |
|
1393 | | - await temp_file.flush() |
1394 | | - |
1395 | 1395 | # Wrap the call in a concrete no-arg function to avoid overload issues during lint. |
1396 | 1396 | def _upload_logs() -> storage.UploadSummary: |
1397 | 1397 | return storage_client.upload_objects( |
1398 | | - source=str(temp_file.name), |
| 1398 | + source=tmp_path, |
1399 | 1399 | destination_prefix=self.workflow_id, |
1400 | 1400 | destination_name=file_name, |
1401 | 1401 | ) |
1402 | 1402 |
|
1403 | 1403 | await asyncio.to_thread(_upload_logs) |
1404 | 1404 |
|
1405 | 1405 | await progress_writer.report_progress_async() |
| 1406 | + finally: |
| 1407 | + # Clean up the temp file ourselves |
| 1408 | + try: |
| 1409 | + os.unlink(tmp_path) |
| 1410 | + except OSError: |
| 1411 | + pass |
1406 | 1412 |
|
1407 | 1413 | semaphore = asyncio.Semaphore(CONCURRENT_UPLOADS) |
1408 | 1414 |
|
|
0 commit comments