Fix: socket permissions para nginx

This commit is contained in:
2026-05-21 23:21:41 -06:00
parent b574ae1ed3
commit 28faa727b1
32 changed files with 2144 additions and 6 deletions
+84
View File
@@ -0,0 +1,84 @@
<?php
namespace App\Jobs;
use App\Models\Alumno;
use App\Models\Promocion;
use App\Models\WhatsappLog;
use App\Services\WhatsAppService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class EnviarPromocionJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $tries = 3;
public int $backoff = 60;
public function __construct(
public Promocion $promocion,
public Alumno $alumno
) {}
public function handle(WhatsAppService $whatsapp): void
{
$this->alumno->refresh();
if ($this->alumno->opt_out) {
return;
}
$telefono = $this->alumno->telefonoWhatsapp();
if (!$telefono) {
WhatsappLog::create([
'alumno_id' => $this->alumno->id,
'telefono' => 'sin_telefono',
'tipo' => 'error',
'mensaje' => 'Alumno sin teléfono registrado',
'payload' => ['promocion_id' => $this->promocion->id],
]);
$this->actualizarPivot('fallido', null);
return;
}
try {
$mensajeId = $whatsapp->enviarPromocion($telefono, $this->promocion);
} catch (\RuntimeException $e) {
WhatsappLog::create([
'alumno_id' => $this->alumno->id,
'telefono' => $telefono,
'tipo' => 'error',
'mensaje' => $e->getMessage(),
'payload' => ['promocion_id' => $this->promocion->id],
]);
$this->actualizarPivot('fallido', null);
return;
}
WhatsappLog::create([
'alumno_id' => $this->alumno->id,
'telefono' => $telefono,
'tipo' => 'enviado',
'mensaje' => $this->promocion->titulo,
'payload' => ['promocion_id' => $this->promocion->id, 'whatsapp_id' => $mensajeId],
]);
$this->actualizarPivot('enviado', $mensajeId);
}
private function actualizarPivot(string $status, ?string $mensajeId): void
{
$this->promocion->alumnos()->updateExistingPivot($this->alumno->id, [
'status_envio' => $status,
'enviado_at' => now(),
'whatsapp_mensaje_id' => $mensajeId,
]);
}
}