← Zurück zu Team für Laravel und React

Skill · Version 1.0.0

Laravel-Warteschlangen und Ereignisse

Organisiert Hintergrundarbeit mit begrenzten Wiederholungen, dauerhaften Ergebnissen und sauberen Transaktions- und Mandantengrenzen.

laravel-queues-events

Teammitglieder mit diesem Skill

Entdecke, wie der Skill hilft

Wann ist der Skill hilfreich?

Nutze diesen Skill für Exporte oder Integrationen außerhalb der Anfragelebensdauer.

Wobei hilft er dir?

  • Schützt Jobs gegen Duplikate mit klaren Zeit- und Wiederholungsgrenzen.
  • Startet abhängige Arbeit nach Commit und behandelt geänderte Datensätze.
  • Verhindert übertragene Mandanten- oder Anmeldedaten langlebiger Worker.

Das könntest du fragen

Baue einen Exportjob für doppelte Zustellung und Worker-Neustart mit korrektem Mandantenbereich und Fehlerstatus. Exportiere zwei Mandanten nacheinander im selben Worker und wiederhole einen Auftrag. Pro Auftrag entsteht ein abgegrenztes Artefakt ohne übernommenen Mandantenkontext.

Ausführliche Dokumentation

Hier findest du die ursprüngliche Anleitung, Beispiele und Prüfschritte des Skills in ihrer Originalsprache.

Details…Weniger anzeigen

Queues, Events & Scheduler

Queued jobs, retries and idempotency

  • Offload slow or external work (emails, webhooks, third-party APIs, exports, media processing) to ShouldQueue jobs. Never treat a queued job or event listener as guaranteed to run exactly once.
  • Make every job idempotent: guard side effects with state checks, unique database constraints, idempotency keys or ShouldBeUnique, so retries or duplicate dispatches never double-charge, double-send or corrupt records.
  • Set explicit $tries, $backoff (array of seconds), $timeout and $maxExceptions, and implement failed(\Throwable $e) to record permanent failure and clean up partial state.
  • Ensure the queue connection's retry_after in config/queue.php is strictly greater than the job's $timeout; otherwise a worker can pick up a second copy while the first is still running.

Payloads, transactions and worker state

  • Pass Eloquent models (via SerializesModels, which stores only the model identifier and re-queries on execution) or scalar IDs — never serialize large collections, request objects or binary blobs into the queue payload. Handle deleted or stale models cleanly when the job runs.
  • When dispatching a job or event inside a database transaction (or from a model observer), implement ShouldDispatchAfterCommit or call ->afterCommit() so workers never read uncommitted rows.
  • In long-lived queue workers (queue:work, Horizon, Octane), never leak static state, singleton properties, auth state or tenant context from one job or request into the next. Explicitly pass and restore tenant context per job, and note when a deploy requires php artisan queue:restart.

Events, notifications and scheduler

  • Use Events and Listeners to decouple domain side effects from the primary action, and Notifications (ShouldQueue) for user-facing messages across mail, database or Slack channels.
  • Keep scheduled closures/commands in routes/console.php (or app/Console/Kernel.php in Laravel 10) thin by delegating to services or jobs. Add ->withoutOverlapping() on tasks that could run past their interval and ->onOneServer() in multi-server deployments.

Enthaltene Dateien 2

  • LICENSE.txt
  • SKILL.md