Export users 500k+ lines, seed, supervisord setup
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Jobs\UsersExport;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class UserExportController extends Controller
|
||||
{
|
||||
public function status()
|
||||
{
|
||||
$status = Cache::remember('export_status', now()->addMinutes(2), function () {
|
||||
return 'standby';
|
||||
});
|
||||
|
||||
$lastExportFile = Cache::get('last_export_file');
|
||||
|
||||
return [
|
||||
'export_status' => $status,
|
||||
'last_export_file' => $lastExportFile
|
||||
];
|
||||
}
|
||||
|
||||
public function counter()
|
||||
{
|
||||
$currentCount = Cache::remember('users_count', now()->addMinutes(2), function () {
|
||||
return User::count();
|
||||
});
|
||||
|
||||
return [
|
||||
'count' => $currentCount,
|
||||
];
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
$status = cache('export_status');
|
||||
if ($status === 'progress') {
|
||||
return [
|
||||
'export_status' => $status,
|
||||
];
|
||||
}
|
||||
|
||||
Cache::forever('export_status', 'progress');
|
||||
|
||||
UsersExport::dispatch();
|
||||
|
||||
return [
|
||||
'export_status' => 'started',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user