# Quick Start - Import 380K Questions

## ⚡ **3 BƯỚC ĐƠN GIẢN**

---

## **BƯỚC 1: Start Queue Worker** (5 giây)

```bash
cd /var/www/html/lms_hocmai
php artisan queue:work --timeout=90000 &
```

✅ Done! Worker đang chạy background.

⚠️ **LƯU Ý:** Không tắt terminal này hoặc dùng supervisor!

---

## **BƯỚC 2: Start Import** (10 giây)

### **Option A: Import TẤT CẢ 1 lần** (Đơn giản)

```bash
curl -X POST 'https://lmsnew.hocmai.net/api/speakup/import-background' \
  -H 'Content-Type: application/json' \
  -d '{
    "start_id": 1,
    "end_id": 380361,
    "batch_size": 100
  }'
```

**Response:**
```json
{
    "job_id": "import_20251114032644_abc12345",
    "total_questions": 380361,
    "check_progress_url": "https://.../import-progress/import_20251114032644_abc12345"
}
```

**⏱️ Thời gian:** ~3-4 ngày

---

### **Option B: 4 Jobs Song Song** (Nhanh gấp 4 lần - RECOMMENDED)

```bash
# Start 4 workers
php artisan queue:work --timeout=90000 &
php artisan queue:work --timeout=90000 &
php artisan queue:work --timeout=90000 &
php artisan queue:work --timeout=90000 &

# Start 4 jobs:
curl -X POST 'https://lmsnew.hocmai.net/api/speakup/import-background' \
  -d '{"start_id": 1, "end_id": 95000}'

curl -X POST 'https://lmsnew.hocmai.net/api/speakup/import-background' \
  -d '{"start_id": 95001, "end_id": 190000}'

curl -X POST 'https://lmsnew.hocmai.net/api/speakup/import-background' \
  -d '{"start_id": 190001, "end_id": 285000}'

curl -X POST 'https://lmsnew.hocmai.net/api/speakup/import-background' \
  -d '{"start_id": 285001, "end_id": 380361}'
```

**⏱️ Thời gian:** ~1 ngày

---

## **BƯỚC 3: Monitor Progress** (Mỗi 1 phút)

```bash
# Lấy job_id từ bước 2
JOB_ID="import_20251114032644_abc12345"

# Check progress
curl "https://lmsnew.hocmai.net/api/speakup/import-progress/$JOB_ID"
```

**Response:**
```json
{
    "status": "running",
    "progress": {
        "percentage": 25.50,
        "processed": 97000,
        "remaining": 283361,
        "current_id": 97000
    },
    "stats": {
        "imported": 94000,
        "not_found": 400,
        "errors": 100
    },
    "time": {
        "eta_formatted": "05:30:00"  // Còn 5.5 giờ
    }
}
```

---

## 🎉 **XONG! CỰC KỲ ĐƠN GIẢN!**

```
Bước 1: Start worker     (5s)
Bước 2: Start import     (10s)
Bước 3: Đợi + Monitor    (1-4 ngày)
```

---

## 📋 **COMMANDS CHEATSHEET**

```bash
# Start worker
php artisan queue:work --timeout=90000 &

# Start import ALL
curl -X POST 'https://lmsnew.hocmai.net/api/speakup/import-background' \
  -d '{"start_id": 1, "end_id": 380361}'

# Check progress
curl 'https://lmsnew.hocmai.net/api/speakup/import-progress/JOB_ID'

# List all jobs
curl 'https://lmsnew.hocmai.net/api/speakup/import-jobs'

# Cancel job
curl -X POST 'https://lmsnew.hocmai.net/api/speakup/import-cancel/JOB_ID'

# Check stats
curl 'https://lmsnew.hocmai.net/api/speakup/import-stats'
```

---

## 🚨 **IMPORTANT NOTES**

### **1. Queue Worker PHẢI chạy!**

```bash
# Check worker đang chạy không:
ps aux | grep "queue:work"

# Nếu không có → Start:
php artisan queue:work --timeout=90000 &
```

---

### **2. Không tắt server/terminal**

- Option 1: Dùng `screen` hoặc `tmux`
- Option 2: Dùng supervisor (production)
- Option 3: Run as daemon

---

### **3. Monitor disk space**

```bash
# Check disk
df -h

# Import sẽ tạo ~2.5GB data
# Cần ít nhất 5GB free space
```

---

## ⏱️ **THỜI GIAN DỰ KIẾN**

| Setup | Workers | Thời gian |
|-------|---------|-----------|
| 1 Job | 1 Worker | ~3-4 ngày |
| 4 Jobs | 4 Workers | ~1 ngày ⭐ |
| 8 Jobs | 8 Workers | ~12 giờ |

**Recommend:** 4 Jobs + 4 Workers = ~1 ngày

---

## 📱 **COPY/PASTE READY**

### **Để import 380K questions NGAY BÂY GIỜ:**

```bash
# Terminal 1: Queue worker
cd /var/www/html/lms_hocmai && php artisan queue:work --timeout=90000

# Terminal 2: Start import
curl -X POST 'https://lmsnew.hocmai.net/api/speakup/import-background' \
  -H 'Content-Type: application/json' \
  -d '{"start_id": 1, "end_id": 380361}'

# Copy job_id từ response, rồi check progress:
curl 'https://lmsnew.hocmai.net/api/speakup/import-progress/PASTE_JOB_ID_HERE'
```

---

## 🎉 **BẮT ĐẦU NGAY!**

**Tất cả đã sẵn sàng! Chỉ cần chạy 2 lệnh trên!** 🚀

