261019_01_ENH: 리스트 비동기 작업 동시 실행 제한 및 진행 상태 UI 개선, 미사용 참조 정리

This commit is contained in:
2026-10-19 14:22:07 +09:00
parent 4e51530922
commit d2e826702e
46 changed files with 1398 additions and 406 deletions

156
src/types/list-job.ts Normal file
View File

@@ -0,0 +1,156 @@
export type ListJobStatus = 'QUEUED' | 'RUNNING' | 'CANCEL_REQUESTED' | 'SUCCEEDED' | 'FAILED' | 'CANCELLED' | 'REJECTED'
// 배정·배정 초기화는 LIST_ASSIGN 하나로 통합됐다. 두 명령은 operation(ASSIGN/RESET)으로만 구분한다.
export const LIST_JOB_TYPES = [
'LIST_UPLOAD', 'LIST_RESET', 'LIST_UPDATE', 'LIST_ASSIGN',
'LIST_DOWNLOAD', 'CONTACT_HISTORY_DOWNLOAD', 'UPDATE_HISTORY_DOWNLOAD', 'ITEM_ZIP_DOWNLOAD',
'EMAIL_BULK', 'SMS_BULK', 'KKO_BULK',
] as const
export type ListJobType = (typeof LIST_JOB_TYPES)[number]
export const isListJobType = (value: unknown): value is ListJobType =>
typeof value === 'string' && (LIST_JOB_TYPES as readonly string[]).includes(value)
/** LIST_ASSIGN 작업의 명령. 다른 jobType은 null이다. */
export type ListJobOperation = 'ASSIGN' | 'RESET'
const isOperationField = (value: unknown) => value === undefined || value === null || value === 'ASSIGN' || value === 'RESET'
export type ListJob = {
jobKey: string
jobType: string
operation?: ListJobOperation | null
jobStatus: ListJobStatus
jobStage: string
totalSidCnt: number | null
completedSidCnt: number
completedChunkCnt: number
failedSidCnt: number
processedSidCnt: number
remainingSidCnt: number | null
progress: Record<string, unknown> | null
failedChunkNo?: number | null
errorCode: string | null
errorMessage: string | null
cancelReason: string | null
regDt: string
startedDt: string | null
finishedDt: string | null
resultFiles: { index: number; type: string; fileName: string; sizeBytes: number; ready: boolean }[]
}
/** 프로젝트에서 진행 중인 업로드·초기화. 다른 사용자 작업이면 jobKey는 null이다. */
export type UploadResetActiveJob = {
jobType: 'LIST_UPLOAD' | 'LIST_RESET'
jobStatus: ListJobStatus
jobStage: string
totalSidCnt: number | null
processedSidCnt: number
mine: boolean
jobKey: string | null
}
export type UploadResetActive = { active: boolean; job: UploadResetActiveJob | null }
export type ListJobFailurePage = { total: number; offset: number; items: Record<string, unknown>[] }
/** 새 작업 접수를 막고 있는 작업. 타인 작업이면 jobKey는 null이다. */
export type ListJobBlocker = {
jobType: string
operation: ListJobOperation | null
jobStatus: ListJobStatus
blockingPhase: 'ACTIVE' | 'FINALIZING'
requestUserId: string
requestUserName: string | null
mine: boolean
jobKey: string | null
regDt: string
}
export type ListJobAvailability = {
requestedJobType: string
allowed: boolean
reasonCode: string | null
blockerCount: number
blockers: ListJobBlocker[]
}
export const isActiveListJob = (status: ListJobStatus) =>
status === 'QUEUED' || status === 'RUNNING' || status === 'CANCEL_REQUESTED'
const statuses: string[] = ['QUEUED', 'RUNNING', 'CANCEL_REQUESTED', 'SUCCEEDED', 'FAILED', 'CANCELLED', 'REJECTED']
const isJobKeyOrNull = (value: unknown) => value === null || (typeof value === 'string' && /^[a-f0-9]{32}$/.test(value))
export function parseListJob(value: unknown): ListJob {
if (!value || typeof value !== 'object') throw new Error('작업 응답이 올바르지 않습니다.')
const job = value as Record<string, unknown>
if (typeof job.jobKey !== 'string' || !/^[a-f0-9]{32}$/.test(job.jobKey)
|| typeof job.jobType !== 'string' || typeof job.jobStage !== 'string'
|| typeof job.jobStatus !== 'string' || !statuses.includes(job.jobStatus)
|| !isOperationField(job.operation)
|| !(job.failedChunkNo === undefined || job.failedChunkNo === null
|| (typeof job.failedChunkNo === 'number' && Number.isInteger(job.failedChunkNo) && job.failedChunkNo > 0))
|| !['completedSidCnt', 'completedChunkCnt', 'failedSidCnt', 'processedSidCnt'].every(key => typeof job[key] === 'number')
|| !(job.totalSidCnt === null || typeof job.totalSidCnt === 'number')
|| !Array.isArray(job.resultFiles)
|| !job.resultFiles.every(file => file && typeof file === 'object'
&& typeof file.index === 'number' && typeof file.fileName === 'string'
&& typeof file.sizeBytes === 'number' && typeof file.ready === 'boolean')) {
throw new Error('작업 응답이 올바르지 않습니다.')
}
return value as ListJob
}
export function parseMyActiveListJobs(value: unknown): ListJob[] {
if (!value || typeof value !== 'object' || !Array.isArray((value as Record<string, unknown>).items)) {
throw new Error('작업 목록 응답이 올바르지 않습니다.')
}
return ((value as Record<string, unknown>).items as unknown[]).map(parseListJob)
}
export function parseUploadResetActive(value: unknown): UploadResetActive {
if (!value || typeof value !== 'object') throw new Error('진행 상태 응답이 올바르지 않습니다.')
const body = value as Record<string, unknown>
if (typeof body.active !== 'boolean') throw new Error('진행 상태 응답이 올바르지 않습니다.')
if (body.job === null) return { active: body.active, job: null }
const job = body.job as Record<string, unknown> | undefined
if (!job || typeof job !== 'object'
|| (job.jobType !== 'LIST_UPLOAD' && job.jobType !== 'LIST_RESET')
|| typeof job.jobStatus !== 'string' || !statuses.includes(job.jobStatus)
|| typeof job.jobStage !== 'string' || typeof job.processedSidCnt !== 'number' || typeof job.mine !== 'boolean'
|| !(job.totalSidCnt === null || typeof job.totalSidCnt === 'number')
|| !isJobKeyOrNull(job.jobKey)) {
throw new Error('진행 상태 응답이 올바르지 않습니다.')
}
return { active: body.active, job: job as UploadResetActiveJob }
}
const isBlocker = (value: unknown): value is ListJobBlocker => {
if (!value || typeof value !== 'object') return false
const blocker = value as Record<string, unknown>
return typeof blocker.jobType === 'string'
&& (blocker.operation === null || blocker.operation === 'ASSIGN' || blocker.operation === 'RESET')
&& typeof blocker.jobStatus === 'string' && statuses.includes(blocker.jobStatus)
&& (blocker.blockingPhase === 'ACTIVE' || blocker.blockingPhase === 'FINALIZING')
&& typeof blocker.requestUserId === 'string'
&& (blocker.requestUserName === null || typeof blocker.requestUserName === 'string')
&& typeof blocker.mine === 'boolean'
&& isJobKeyOrNull(blocker.jobKey)
&& typeof blocker.regDt === 'string'
}
export function parseListJobAvailability(value: unknown): ListJobAvailability {
if (!value || typeof value !== 'object') throw new Error('작업 가능 여부 응답이 올바르지 않습니다.')
const body = value as Record<string, unknown>
if (typeof body.requestedJobType !== 'string' || typeof body.allowed !== 'boolean'
|| !(body.reasonCode === null || typeof body.reasonCode === 'string')
|| typeof body.blockerCount !== 'number' || !Array.isArray(body.blockers) || !body.blockers.every(isBlocker)) {
throw new Error('작업 가능 여부 응답이 올바르지 않습니다.')
}
return {
requestedJobType: body.requestedJobType,
allowed: body.allowed,
reasonCode: body.reasonCode,
blockerCount: body.blockerCount,
blockers: body.blockers,
}
}