# Video Upload Queue Setup Guide

## Overview
Large videos (1GB+) are now uploaded asynchronously via Laravel's queue system to prevent timeouts and improve user experience.

## Configuration Steps

### 1. Update `.env` File
Change the queue connection from `sync` to `database`:

```env
QUEUE_CONNECTION=database
```

### 2. Database Migration
The `jobs` table already exists. Verify it's created:
```bash
php artisan migrate
```

### 3. Start Queue Worker
Run the queue worker to process video uploads:

```bash
# Single worker
php artisan queue:work

# With specific queue
php artisan queue:work --queue=default

# Daemonize with supervisor (production)
php artisan queue:work --daemon
```

### 4. Monitor Queue Jobs
View pending jobs:
```bash
php artisan queue:monitor
php artisan queue:failed  # View failed jobs
php artisan queue:retry all  # Retry failed jobs
```

## How It Works

1. **User submits form** → Files stored to temporary location (`temp_videos/`, `temp_thumbnails/`)
2. **Content record created** → Empty video/thumbnail fields
3. **Job dispatched** → File processing queued
4. **Queue worker picks up job** → Moves files from temp to final location
5. **Database updated** → Video/thumbnail paths saved to content record

## Features

✅ **Timeout Prevention** - Job timeout set to 30 minutes for large files
✅ **Error Logging** - Failed uploads logged to `storage/logs/`
✅ **Automatic Cleanup** - Temporary files deleted after processing
✅ **Old File Deletion** - Previous version removed when updating
✅ **Consistent UX** - User gets immediate feedback while processing happens

## Troubleshooting

### Queue Not Processing
- Ensure `QUEUE_CONNECTION=database` in `.env`
- Check queue worker is running: `php artisan queue:work`
- Run `php artisan migrate` to ensure jobs table exists

### Files Stuck in temp_videos/
- Check failed jobs: `php artisan queue:failed`
- Manually retry: `php artisan queue:retry all`
- Check logs: `storage/logs/laravel.log`

### Job Timeout
- Increase timeout in `app/Jobs/UploadVideoJob.php` (currently 30 min)
- Adjust based on your server speed and network

## Files Modified
- `app/Http/Controllers/Backend/AdminNew/ContentCreatorController.php` - Updated to use queue
- `app/Jobs/UploadVideoJob.php` - New job for handling uploads
