Choose your preferred language for documentation:
🇺🇸 English | View English Documentation |
🇮🇩 Bahasa Indonesia | Lihat Dokumentasi Bahasa Indonesia |
Laravel Job Batching with Realtime Progress is a powerful package that allows you to execute batch jobs with real-time progress tracking. Monitor your job execution progress live using WebSocket technology powered by Pusher.
- ✨ Features
- 📋 Requirements
- ⚙️ Installation
- 🔧 Configuration
- 🛠️ Implementation
- 📊 JavaScript Setup
- 📈 API Response
- 🤝 Contributing
- 📝 Changelog
- 👥 Credits
- 📄 License
- 🔄 Real-time Progress Tracking - Monitor job execution progress in real-time
- 📡 WebSocket Integration - Uses Pusher for instant updates
- 🎯 Batch Processing - Handle multiple jobs efficiently
- 🔌 Easy Integration - Simple setup with Laravel projects
- 📊 Progress Metrics - Get detailed progress information
- 🎨 Customizable - Flexible implementation for various use cases
Create necessary migration tables:
# Create job table
php artisan queue:table
# Create job batches table
php artisan queue:batches-table
# Run migrations
php artisan migratecomposer require yogameleniawan/realtime-job-batchingInstall Pusher PHP SDK:
composer require pusher/pusher-php-server-
Create Pusher App: Visit Pusher Dashboard to create a new Channels app
-
Environment Variables: Add these variables to your
.envfile:
PUSHER_APP_ID=your_pusher_app_id
PUSHER_APP_KEY=your_pusher_app_key
PUSHER_APP_SECRET=your_pusher_app_secret
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1-
Create Repository Directory: Create folder
app/Repositoriesin your project -
Create Repository Class: For example,
VerificationRepository.php -
Implement Interface: Your repository must implement
RealtimeJobBatchInterface
<?php
namespace App\Repositories;
use Illuminate\Support\Collection;
use YogaMeleniawan\JobBatchingWithRealtimeProgress\Interfaces\RealtimeJobBatchInterface;
class VerificationRepository implements RealtimeJobBatchInterface
{
/**
* Get all data to be processed
* @return Collection
*/
public function get_all(): Collection
{
// Return collection of data to be processed
return collect([
// Your data here
]);
}
/**
* Process individual data item
* @param mixed $data
* @return void
*/
public function save($data): void
{
// Your business logic here
// Update/delete/process the data
}
}Create a controller method to handle your job process:
<?php
namespace App\Http\Controllers;
use YogaMeleniawan\JobBatchingWithRealtimeProgress\RealtimeJobBatch;
use App\Repositories\VerificationRepository;
class BatchController extends Controller
{
public function executeVerification()
{
$result = RealtimeJobBatch::setRepository(new VerificationRepository())
->execute(name: 'User Verification Process');
return response()->json([
'message' => 'Batch job started successfully',
'batch_id' => $result->id
]);
}
}setRepository(RealtimeJobBatchInterface $repository): Sets the repository class to useexecute(string $name): Executes the job batch with a custom name
Add this script to your blade template:
<script src="https://js.pusher.com/7.2/pusher.min.js"></script>
<script>
// Initialize Pusher
var pusher = new Pusher('YOUR_PUSHER_APP_KEY', {
cluster: 'mt1'
});
// Listen for progress updates
var progressChannel = pusher.subscribe('channel-job-batching');
progressChannel.bind('broadcast-job-batching', function(data) {
console.log('Progress Update:', data);
// Update your progress bar
updateProgressBar(data.progress);
updateStats(data);
});
// Listen for completion
var finishChannel = pusher.subscribe('channel-finished-job');
finishChannel.bind('request-finished-job', function(data) {
if (data.finished === true) {
console.log('Job completed!');
resetProgressBar();
}
});
// Helper functions
function updateProgressBar(progress) {
document.getElementById('progress-bar').style.width = progress + '%';
document.getElementById('progress-text').textContent = progress + '%';
}
function updateStats(data) {
document.getElementById('total-jobs').textContent = data.total;
document.getElementById('pending-jobs').textContent = data.pending;
}
function resetProgressBar() {
updateProgressBar(0);
// Add your completion logic here
}
</script>For React, Vue, or other JavaScript frameworks, check the Pusher documentation.
The WebSocket will send progress updates in this format:
{
"finished": false,
"progress": 10,
"pending": 90,
"total": 100,
"data": {
"batch_id": "uuid-string",
"name": "User Verification Process",
"started_at": "2024-01-01T10:00:00Z"
}
}finished: Boolean indicating if the batch is completeprogress: Number of completed jobspending: Number of remaining jobstotal: Total number of jobs in the batchdata: Additional batch information
We welcome contributions! Please see our Contributing Guidelines for details.
Please see CHANGELOG for more information about recent changes.
- Yoga Meleniawan Pamungkas - Original Author
- All Contributors - Community Contributors
This project is licensed under the MIT License - see the LICENSE file for details.
Laravel Job Batching with Realtime Progress adalah package yang memungkinkan Anda menjalankan batch job dengan pelacakan progres real-time. Pantau eksekusi job Anda secara langsung menggunakan teknologi WebSocket yang didukung oleh Pusher.
- ✨ Fitur
- 📋 Persyaratan
- ⚙️ Instalasi
- 🔧 Konfigurasi
- 🛠️ Implementasi
- 📊 Setup JavaScript
- 📈 Response API
- 🤝 Kontribusi
- 📝 Changelog
- 👥 Kredit
- 📄 Lisensi
- 🔄 Pelacakan Progres Real-time - Pantau progres eksekusi job secara real-time
- 📡 Integrasi WebSocket - Menggunakan Pusher untuk update instan
- 🎯 Pemrosesan Batch - Menangani multiple job secara efisien
- 🔌 Integrasi Mudah - Setup sederhana dengan proyek Laravel
- 📊 Metrik Progres - Dapatkan informasi progres yang detail
- 🎨 Dapat Dikustomisasi - Implementasi fleksibel untuk berbagai kasus penggunaan
Buat tabel migrasi yang diperlukan:
# Buat tabel job
php artisan queue:table
# Buat tabel job batches
php artisan queue:batches-table
# Jalankan migrasi
php artisan migratecomposer require yogameleniawan/realtime-job-batchingInstall Pusher PHP SDK:
composer require pusher/pusher-php-server-
Buat Aplikasi Pusher: Kunjungi Dashboard Pusher untuk membuat aplikasi Channels baru
-
Variabel Environment: Tambahkan variabel ini ke file
.envAnda:
PUSHER_APP_ID=your_pusher_app_id
PUSHER_APP_KEY=your_pusher_app_key
PUSHER_APP_SECRET=your_pusher_app_secret
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1-
Buat Direktori Repository: Buat folder
app/Repositoriesdi proyek Anda -
Buat Class Repository: Misalnya,
VerificationRepository.php -
Implement Interface: Repository Anda harus mengimplementasikan
RealtimeJobBatchInterface
<?php
namespace App\Repositories;
use Illuminate\Support\Collection;
use YogaMeleniawan\JobBatchingWithRealtimeProgress\Interfaces\RealtimeJobBatchInterface;
class VerificationRepository implements RealtimeJobBatchInterface
{
/**
* Dapatkan semua data yang akan diproses
* @return Collection
*/
public function get_all(): Collection
{
// Return collection data yang akan diproses
return collect([
// Data Anda di sini
]);
}
/**
* Proses item data individual
* @param mixed $data
* @return void
*/
public function save($data): void
{
// Logic bisnis Anda di sini
// Update/delete/proses data
}
}Buat method controller untuk menangani proses job Anda:
<?php
namespace App\Http\Controllers;
use YogaMeleniawan\JobBatchingWithRealtimeProgress\RealtimeJobBatch;
use App\Repositories\VerificationRepository;
class BatchController extends Controller
{
public function executeVerification()
{
$result = RealtimeJobBatch::setRepository(new VerificationRepository())
->execute(name: 'Proses Verifikasi User');
return response()->json([
'message' => 'Batch job berhasil dimulai',
'batch_id' => $result->id
]);
}
}setRepository(RealtimeJobBatchInterface $repository): Mengatur class repository yang akan digunakanexecute(string $name): Menjalankan job batch dengan nama kustom
Tambahkan script ini ke template blade Anda:
<script src="https://js.pusher.com/7.2/pusher.min.js"></script>
<script>
// Inisialisasi Pusher
var pusher = new Pusher('YOUR_PUSHER_APP_KEY', {
cluster: 'mt1'
});
// Listen untuk update progres
var progressChannel = pusher.subscribe('channel-job-batching');
progressChannel.bind('broadcast-job-batching', function(data) {
console.log('Update Progres:', data);
// Update progress bar Anda
updateProgressBar(data.progress);
updateStats(data);
});
// Listen untuk penyelesaian
var finishChannel = pusher.subscribe('channel-finished-job');
finishChannel.bind('request-finished-job', function(data) {
if (data.finished === true) {
console.log('Job selesai!');
resetProgressBar();
}
});
// Helper functions
function updateProgressBar(progress) {
document.getElementById('progress-bar').style.width = progress + '%';
document.getElementById('progress-text').textContent = progress + '%';
}
function updateStats(data) {
document.getElementById('total-jobs').textContent = data.total;
document.getElementById('pending-jobs').textContent = data.pending;
}
function resetProgressBar() {
updateProgressBar(0);
// Tambahkan logic completion Anda di sini
}
</script>Untuk React, Vue, atau framework JavaScript lainnya, periksa dokumentasi Pusher.
WebSocket akan mengirim update progres dalam format ini:
{
"finished": false,
"progress": 10,
"pending": 90,
"total": 100,
"data": {
"batch_id": "uuid-string",
"name": "Proses Verifikasi User",
"started_at": "2024-01-01T10:00:00Z"
}
}finished: Boolean yang menunjukkan apakah batch sudah selesaiprogress: Jumlah job yang sudah selesaipending: Jumlah job yang tersisatotal: Total jumlah job dalam batchdata: Informasi tambahan batch
Kami menyambut kontribusi! Silakan lihat Panduan Kontribusi kami untuk detail.
Silakan lihat CHANGELOG untuk informasi lebih lanjut tentang perubahan terbaru.
- Yoga Meleniawan Pamungkas - Penulis Asli
- Semua Kontributor - Kontributor Komunitas
Proyek ini dilisensikan di bawah Lisensi MIT - lihat file LICENSE untuk detail.

