Увійти Реєстрація
Вакансії
Вакансії Laravel Компанії Статистика
Підготовка
Як підготуватися Співбесіди Тестування Документація
Блог
Всі статті Серії
Екосистема
Пакети Ресурси Проєкти Інструменти Події Відео
Інше
Про нас Реклама

Laravel Once Run

mishabachkur/laravel-once-run

Artisan commands that run exactly once during deployment, like migrations for data

19

Поділитись

README

Laravel Once Run

Run Artisan commands exactly once during deployment, safe by default for blue-green and multi-server setups. Migrations stay for schema changes; once-run commands handle backfills and other one-time data tasks.

Requires PHP 8.2+ and Laravel 12 or 13.

Why this package

  • The lock is always on. There is no flag to forget in a deploy script, and it lasts 24 hours, so a long backfill is not started twice. It needs a shared cache store (see below).
  • Plain Artisan commands. Output, options and dependency injection work as usual.
  • Synchronous. A command counts as done only when handle() succeeds.
  • Interrupted runs are visible. The runner warns when it retries a command that did not finish.

If you need checkpoints to resume a long operation partway, look at directorytree/operations. If you want queued operations, look at timokoerber/laravel-one-time-operations.

Installation

composer require mishabachkur/laravel-once-run
php artisan vendor:publish --tag=once-run-migrations
php artisan migrate

Publish the config (--tag=once-run-config) or the stub (--tag=once-run-stubs) to change defaults.

The runner lock lives in a cache store that every deploying server or container must share. Set it with ONCE_RUN_CACHE_STORE=redis (or database, memcached, dynamodb). A file, array or null store does not prevent parallel runs, and once:run warns about it.

Usage

php artisan make:once_run BackfillUserUuids

This creates a timestamped class in app/Console/Commands/OnceRun. Implement handle(). Run pending commands after migrations in your deploy script:

php artisan migrate --force
php artisan once:run --force --no-interaction
Option Effect
--pretend List pending commands without running them
--force Run without confirmation
--release-lock Release a lock left by a killed process

How it works

  • Every registered command extending MishaBachkur\OnceRun\OnceRunCommand is picked up and run in class name order.
  • Executions are recorded by class name in once_run_commands. Never rename or move a deployed command.
  • A failure stops the runner with a non-zero exit code. The failed command runs again next time.
  • Return true from runsInTransaction() for DB-only work, so the work and its record are committed together.
  • The lock lasts 24 hours by default. SIGINT and SIGTERM release it, SIGKILL does not.

Writing safe commands

  • Make them idempotent: a retry must not duplicate changes.
  • Keep them synchronous and non-interactive, with no required arguments.
  • Dispatching a queued job does not mean the work is done.
  • Calling a command directly by its signature bypasses tracking and the lock.

Читати в документації

Коментарі

Увійдіть, щоб залишити коментар

Будьте першим, хто залишить коментар!

Схожі пакети

Laravel Octane

laravel/octane

Прискорює застосунок, тримаючи його в пам'яті між запитами через FrankenPHP, Swoole або RoadRunner. Прибирає завантаження фреймворку з кожного запиту, даючи кратний приріст пропускної здатності.

4,035 v2.19.1 13 7

Laravel Sail

laravel/sail

Локальне середовище розробки на Docker без знання Docker: PHP, база даних, Redis, Meilisearch і Mailpit піднімаються однією командою. Стандартний спосіб запустити Laravel на новій машині.

1,912 v1.67.0 13 7

Laravel Reverb

laravel/reverb

Власний WebSocket-сервер для Laravel: real-time мовлення без сторонніх сервісів на кшталт Pusher. Сумісний із протоколом Pusher, тож Echo на фронтенді працює без змін.

1,598 v1.11.1 13 7

Laravel Prompts

laravel/prompts

Гарні інтерактивні поля для консольних команд: запити, паролі, вибір зі списку, автодоповнення і прогрес-бари з валідацією. Використовується самим Artisan і доступне у ваших командах.

721 v0.3.23 9

Laravel Pennant

laravel/pennant

Feature-флаги для поступового викочування функціоналу: увімкнення для частини користувачів, A/B-тести і швидке вимкнення без деплою. Значення зберігаються в базі або в пам'яті.

590 v1.26.0 13 3