fix: [subscription] 내보내기 stuck 문제 해결 - 동기 처리로 전환

- pending 상태로 영원히 남던 DataExport 문제 수정
- 미구현 비동기 Job 대신 ExportService::store() 동기 처리
- 5분 이상 stuck된 export 자동 만료 처리
- 파일 다운로드 엔드포인트 추가 (GET /export/{id}/download)
This commit is contained in:
김보곤
2026-03-18 14:10:43 +09:00
parent 8f215b235b
commit abf5b6896e
3 changed files with 97 additions and 8 deletions

View File

@@ -8,13 +8,17 @@
use App\Http\Requests\V1\Subscription\SubscriptionCancelRequest;
use App\Http\Requests\V1\Subscription\SubscriptionIndexRequest;
use App\Http\Requests\V1\Subscription\SubscriptionStoreRequest;
use App\Services\ExportService;
use App\Services\SubscriptionService;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class SubscriptionController extends Controller
{
public function __construct(
private readonly SubscriptionService $subscriptionService
private readonly SubscriptionService $subscriptionService,
private readonly ExportService $exportService
) {}
/**
@@ -117,12 +121,12 @@ public function usage(): JsonResponse
}
/**
* 내보내기 요청
* 내보내기 요청 (동기 처리)
*/
public function export(ExportStoreRequest $request): JsonResponse
{
return ApiResponse::handle(
fn () => $this->subscriptionService->createExport($request->validated()),
fn () => $this->subscriptionService->createExport($request->validated(), $this->exportService),
__('message.export.requested')
);
}
@@ -137,4 +141,24 @@ public function exportStatus(int $id): JsonResponse
__('message.fetched')
);
}
/**
* 내보내기 파일 다운로드
*/
public function exportDownload(int $id): BinaryFileResponse
{
$export = $this->subscriptionService->getExport($id);
if (! $export->is_downloadable) {
throw new NotFoundHttpException(__('error.export.not_found'));
}
$filePath = storage_path('app/'.$export->file_path);
if (! file_exists($filePath)) {
throw new NotFoundHttpException(__('error.export.not_found'));
}
return response()->download($filePath, $export->file_name);
}
}