보안 인벤토리를 위한 백그라운드 작업
GitLab v19.5요약
이 문서는 보안 인벤토리에서 장기 실행 대량 작업을 추적하는 백그라운드 작업 시스템을 설명합니다. 백그라운드 작업을 사용하면 여러 프로젝트에 걸친 대량 작업을 비동기로 수행할 수 있습니다. 이메일은 작업 완료 후 실패가 발생한 경우에만 전송됩니다.
이 문서는 보안 인벤토리에서 장기 실행 대량 작업을 추적하는 백그라운드 작업 시스템을 설명합니다.
목적#
백그라운드 작업을 사용하면 여러 프로젝트에 걸친 대량 작업을 비동기로 수행할 수 있습니다. 이 시스템은 오류 추적과 실패 시 이메일 알림을 제공합니다.
아키텍처#
흐름#
Mermaid 다이어그램 (8줄)
소스 코드 보기
flowchart LR
A[BulkUpdateService] --> B[BulkUpdateSchedulerWorker]
B --> C[BackgroundOperationBulkUpdateWorker]
C --> D{Failures?}
D -->|Yes| E[Email Notification]
D -->|No| F[Cleanup]
B --> G[Create Redis Operation]
C --> H[Update Counters]- 시작: 사용자가
BulkUpdateService를 통해 대량 작업을 트리거합니다 - 예약:
BulkUpdateSchedulerWorker가 프로젝트를 수집하고 Redis 작업을 생성합니다 - 처리:
BackgroundOperationBulkUpdateWorker가 프로젝트를 배치 단위로 처리합니다 - 완료: 마지막 배치가 완료를 감지하고 실패가 발생한 경우 이메일을 전송합니다
- 정리: 알림 후 Redis 엔티티를 삭제합니다
구성 요소#
| 구성 요소 | 목적 |
|---|---|
Security::Attributes::BulkUpdateSchedulerWorker |
배치 예약 조율, Redis 작업 생성 |
Security::Attributes::BackgroundOperationBulkUpdateWorker |
추적과 함께 프로젝트 처리 |
Gitlab::BackgroundOperations::RedisStore |
Redis 상태 관리 |
Security::BackgroundOperationMailer |
실패 알림 이메일 |
Redis 데이터 구조#
작업 엔티티#
Key: background_operation:{operation_id}
Type: Hash
Fields:
- id: operation ID
- operation_type: type of operation (for example, 'attribute_update')
- user_id: user who initiated
- parameters: JSON with operation-specific params
- status: 'pending' | 'running'
- total_items: total projects to process
- successful_items: count of successful projects
- failed_items: count of failed projects
- created_at: timestamp
TTL: 72 hours
실패 항목 목록#
Key: background_operation:{operation_id}:failed_items
Type: List
Items: JSON objects with:
- entity_id: ID of failed entity (project or group)
- entity_type: 'Project' or 'Group'
- entity_name: name of the entity
- entity_full_path: full path for linking
- error_message: human-readable error
- error_code: machine-readable error code
- created_at: timestamp
TTL: 72 hours
오류 코드#
| 코드 | 의미 |
|---|---|
service_error |
서비스가 오류 응답을 반환함 |
unexpected_error |
예상치 못한 예외 발생 |
이메일 알림#
이메일은 작업 완료 후 실패가 발생한 경우에만 전송됩니다.
이메일에 포함되는 내용은 다음과 같습니다.
- 요약: 총계, 성공 수, 실패 수
- 오류 세부 정보와 링크가 포함된 실패 항목(프로젝트 또는 그룹) 목록
사용법#
작업 생성#
operation_id = Gitlab::BackgroundOperations::RedisStore.create_operation(
operation_type: 'attribute_update',
user_id: user.id,
total_items: projects_count,
parameters: { attribute_ids: [1, 2], mode: 'ADD' }
)
성공 또는 실패 기록#
# Record success
Gitlab::BackgroundOperations::RedisStore.increment_successful(operation_id)
# Record failure for a project
Gitlab::BackgroundOperations::RedisStore.add_failed_item(
operation_id,
entity_id: project.id,
entity_type: 'Project',
entity_name: project.name,
entity_full_path: project.full_path,
error_message: 'Permission denied',
error_code: 'service_error'
)
# Record failure for a group
Gitlab::BackgroundOperations::RedisStore.add_failed_item(
operation_id,
entity_id: group.id,
entity_type: 'Group',
entity_name: group.name,
entity_full_path: group.full_path,
error_message: 'Permission denied',
error_code: 'service_error'
)
작업 상태 확인#
operation = Gitlab::BackgroundOperations::RedisStore.get_operation(operation_id)
# Returns Operation struct with: id, operation_type, user_id, parameters,
# total_items, successful_items, failed_items
failed_items = Gitlab::BackgroundOperations::RedisStore.get_failed_items(operation_id)
# Returns array of failed item hashes
정리#
Gitlab::BackgroundOperations::RedisStore.delete_operation(operation_id)
# Deletes both the operation hash and failed items list