
# 대기열 관리

Queuety는 이름이 지정된 여러 대기열을 지원합니다. 각 작업자는 하나의 대기열 또는 순서가 지정된 대기열 목록을 처리하며([작업자](https://queuety.inline0.dev/ko/docs/features/workers#multi-queue-priorities) 참고), 대기열은 각각 독립적으로 일시 중지하고 재개할 수 있습니다.

## 이름이 지정된 대기열

특정 대기열로 작업을 디스패치합니다.

```php
use Queuety\Queuety;

Queuety::dispatch( 'send_email', $payload )->on_queue( 'emails' );
Queuety::dispatch( 'process_image', $payload )->on_queue( 'media' );
Queuety::dispatch( 'sync_data', $payload )->on_queue( 'sync' );
```

각 대기열의 작업자를 실행합니다.

```bash
wp queuety work --queue=emails
wp queuety work --queue=media
wp queuety work --queue=sync
```

기본 대기열은 `default`입니다. 대기열을 지정하지 않으면 작업은 이곳으로 이동합니다.

## 일시 중지 및 재개

작업자가 새 작업을 가져가지 않도록 대기열을 일시 중지하세요. 이미 처리 중인 작업은 완료되지만 새 작업은 가져오지 않습니다.

```php
Queuety::pause( 'emails' );
Queuety::resume( 'emails' );
```

대기열이 일시 중지되었는지 확인합니다.

```php
if ( Queuety::is_paused( 'emails' ) ) {
    // Queue is paused
}
```

CLI을 통해 확인:

```bash
wp queuety pause emails
wp queuety resume emails
```

작업자를 종료하지 않고 처리를 잠시 멈추려는 배포 또는 유지 관리 시간에 유용합니다.

## 대기열 통계

상태별 작업 수를 가져옵니다.

```php
$stats = Queuety::stats(); // all queues
$stats = Queuety::stats( 'emails' ); // specific queue

// Returns: ['pending' => 12, 'processing' => 3, 'completed' => 150, 'failed' => 2, 'buried' => 1]
```

CLI을 통해 확인:

```bash
wp queuety status
wp queuety status --queue=emails
```

## 보관된 작업

보관된 모든 작업(재시도 횟수를 소진한 후 실패한 작업)을 나열합니다.

```php
$buried = Queuety::buried(); // all queues
$buried = Queuety::buried( 'emails' ); // specific queue
```

다시 시도합니다.

```php
Queuety::retry( $job_id );       // retry a specific job
Queuety::retry_buried();         // retry all buried jobs
```

## 완료된 작업 삭제

데이터베이스를 깔끔하게 유지하려면 오래된 완료 작업을 제거하세요.

```php
$count = Queuety::purge();     // uses QUEUETY_RETENTION_DAYS (default: 7)
$count = Queuety::purge( 30 ); // purge jobs older than 30 days
```

CLI을 통해 확인:

```bash
wp queuety purge
wp queuety purge --older-than=30
```
