Laravel Packagev12.2.0MIT License

Laravel Executor

Laravel Executor turns the steps you run after a deploy into versioned PHP files called executors. Each executor has an up() method that does the work and a down() method that reverses it. php artisan execute runs every executor the server still needs and records the run in a database table, in batches you can roll back, filter by tag, and limit to specific servers.

Run Once or Always

An executor runs a single time per database, or again on every deploy.

Commands and Jobs

Call Artisan commands and dispatch queued jobs from inside an executor.

Batches and Rollback

Every run is recorded in a batch, and the latest batches can be rolled back.

Tags

Group executors with tags and run only the groups you need.

Server Targeting

List the server IP addresses an executor belongs to: other servers skip it, and each listed server keeps its own record.

Status

See every executor with its type, tags, servers, batch and whether it ran.

Quick Tip

Add php artisan execute to your deploy script right after php artisan migrate, and run it on every server.

#Installation

Install the package with Composer and create its table.

#Requirements

  • PHP 8.2, 8.3, 8.4 or 8.5
  • Laravel 12

#Composer Installation

Terminal
composer require pharaonic/laravel-executor

The service provider is registered automatically.

#Run Migrations

The package loads its migration automatically, so the executors table is created with your other migrations:

Terminal
php artisan migrate

To change the migration before it runs, publish it into database/migrations:

Terminal
php artisan vendor:publish --tag=executor-migrations

#Publish Configuration

Publish the configuration only when you need another connection or table name:

Terminal
php artisan vendor:publish --tag=executor-config

The file is published to config/pharaonic/executor.php.

Installation Complete

You're all set! Create your first executor with php artisan make:executor.

#Upgrading

Pick the part for the release you're on: 12.0.x needs a few renames, while 1.x needs a new table and changes to every executor file.

#From 12.0.x

This line keeps the table and the executor classes of 12.0.x. Run php artisan migrate after updating, which adds the server column, then update the case names and check the behavior changes below.

#Executor Types Are Upper Case

The ExecutorType cases are renamed, and the old names are removed. Executors that still use them stop with an Undefined constant error, so update every executor file:

12.0.x12.1.0
ExecutorType::AlwaysExecutorType::ALWAYS
ExecutorType::OnceExecutorType::ONCE

ExecutorType::ALWAYS->name returns ALWAYS. Compare the case itself ($type === ExecutorType::ONCE), call isOnce(), or use label(), which returns Always or Once.

#Behavior Changes

  • An executor with $servers runs only on those servers, including on its first run. In 12.0.x, the first run happened on every server.
  • php artisan execute, execute:rollback and execute:fresh take a lock in the executors table, so servers that deploy at the same time run them one after another, as described in Running Executors.
  • Invalid executor declarations throw InvalidArgumentException, and duplicate executor names throw LogicException, instead of Exception.

#Deprecated Names

DeprecatedUse
php artisan execute:make, php artisan make:executephp artisan make:executor
--tag=config--tag=executor-config
--tag=migrations--tag=executor-migrations

The deprecated names still work.

#From 1.x

On Laravel 12, this line replaces 1.x. Executors become classes with up() and down(), and the executors table has a new shape. Plan the upgrade as a deploy of its own: update the package, recreate the table, then update every executor file.

#1. Update the Package

Composer doesn't move from 1.x to this line on its own, so require it explicitly:

Terminal
composer require pharaonic/laravel-executor:^12.1

#2. Recreate the Table

The executors table has a new shape, and the package doesn't convert the 1.x table:

1.x columnNow
executorname
tag (text)tags (JSON array: cache becomes ["cache"])
servers (new, empty)
batch (1 by default)batch (required, no default)

1.x created the table with the same migration file name, 2024_07_07_000001_create_executors_table, so php artisan migrate treats it as already run and keeps the 1.x table. Recreate the table yourself and copy the records into it, so executors that already ran don't run again. In php artisan tinker:

php artisan tinker
1$rows = DB::table('executors')->orderBy('id')->get();
2 
3Schema::drop('executors');
4DB::table('migrations')->where('migration', '2024_07_07_000001_create_executors_table')->delete();
5Artisan::call('migrate', ['--path' => 'vendor/pharaonic/laravel-executor/database/migrations', '--force' => true]);
6 
7$rows->each(fn ($row) => DB::table('executors')->insert([
8 'type' => $row->type,
9 'name' => $row->executor,
10 'tags' => $row->tag === null ? null : json_encode([$row->tag]),
11 'batch' => $row->batch,
12 'executed' => $row->executed,
13 'last_executed_at' => $row->last_executed_at,
14]));
Back Up First

The records live only in the tinker session between dropping the table and inserting them again. Back up the executors table before you start. If you skip the copy, every ONCE executor runs again on the next php artisan execute.

#3. Update Every Executor File

1.xNow
use Pharaonic\Laravel\Executor\Executor;use Pharaonic\Laravel\Executor\Classes\Executor;
public function handle(): voidpublic function up(): void, plus a down() method
public $tag = 'cache';public $tags = ['cache'];
ExecutorType::Always / ExecutorType::OnceExecutorType::ALWAYS / ExecutorType::ONCE
executors/2024_07_22_100000_clear_cache.php
1use Pharaonic\Laravel\Executor\Enums\ExecutorType;
2use Pharaonic\Laravel\Executor\Executor;
3 
4return new class extends Executor
5{
6 public $type = ExecutorType::Once;
7 
8 public $tag = 'cache';
9 
10 public function handle(): void
11 {
12 $this->command('cache:clear');
13 }
14};
executors/2024_07_22_100000_clear_cache.php
1use Pharaonic\Laravel\Executor\Classes\Executor;
2use Pharaonic\Laravel\Executor\Enums\ExecutorType;
3 
4return new class () extends Executor {
5 public $type = ExecutorType::ONCE;
6 
7 public $tags = ['cache'];
8 
9 public function up(): void
10 {
11 $this->command('cache:clear');
12 }
13 
14 public function down(): void
15 {
16 //
17 }
18};

Keep each file name: it is the executor's name, and the migrated records point at it.

Old Executors Stop the Command

php artisan execute reads every executor file. A file that still extends the 1.x class, uses handle(), or uses ExecutorType::Once stops the whole command with an error, so update all of them before you deploy.

#4. Update Code That Uses the Package

1.xNow
Pharaonic\Laravel\Executor\Facades\ExecutorPool::addPath($path)Pharaonic\Laravel\Executor\Facades\Executor::getPool()->addPath($path)
ExecutorPool::getPaths()Executor::getPool()->getPaths()
php artisan execute:makephp artisan make:executor (the old name still works and prints a deprecation notice)
--tag=migrations--tag=executor-migrations

ExecutorType::ALWAYS->name returns ALWAYS. Compare the case itself ($type === ExecutorType::ONCE), call isOnce(), or use label(), which returns Always or Once.

#What's New

#Configuration

The package works without any configuration. Publish the file when you need another connection or table:

Terminal
php artisan vendor:publish --tag=executor-config
config/pharaonic/executor.php
1return [
2 /**
3 * The database connection that should be used by the executor.
4 */
5 'connection' => env('EXECUTOR_CONNECTION', config('database.default')),
6 
7 /**
8 * The table that should be used to store the executors.
9 */
10 'table' => env('EXECUTOR_TABLE', 'executors'),
11 
12 /**
13 * The name of this server, matched against the executors' `$servers`
14 * next to the server's IP addresses. Give each server a fixed name when
15 * its addresses change, such as in containers.
16 */
17 'server' => env('EXECUTOR_SERVER'),
18 
19 /**
20 * The lock that makes servers deploying at the same time run the
21 * executors one after another. It is a row of the executors table, so
22 * every server that shares the table shares the lock. `seconds` is how
23 * long a run may hold the lock and how long the next server waits for it.
24 */
25 'lock' => [
26 'seconds' => env('EXECUTOR_LOCK_SECONDS', 600),
27 ],
28];
KeyEnvironment variableDefaultDescription
pharaonic.executor.connectionEXECUTOR_CONNECTIONyour default connectionDatabase connection of the executors table
pharaonic.executor.tableEXECUTOR_TABLEexecutorsName of the executors table
pharaonic.executor.serverEXECUTOR_SERVERnoneName of this server for $servers
pharaonic.executor.lock.secondsEXECUTOR_LOCK_SECONDS600How long a run may hold the lock, and how long another server waits for it
Same Database on Every Server

All your servers should share the same executors table. The table is how a ONCE executor knows it already ran, and it holds the lock. When each server has its own application database, point EXECUTOR_CONNECTION at a connection every server shares.

#Basic Usage

Create an executor, describe the work in up(), and run it.

#1. Create an Executor

Terminal
php artisan make:executor WarmCaches

The command creates a timestamped file in the executors folder of your project, such as executors/2026_01_15_120000_warm_caches.php. The file name without .php is the executor's name.

#2. Write the Task

executors/2026_01_15_120000_warm_caches.php
1use Pharaonic\Laravel\Executor\Classes\Executor;
2use Pharaonic\Laravel\Executor\Enums\ExecutorType;
3 
4return new class () extends Executor {
5 public $type = ExecutorType::ONCE;
6 
7 public $tags = [];
8 
9 public $servers = [];
10 
11 public function up(): void
12 {
13 $this->command('optimize');
14 }
15 
16 public function down(): void
17 {
18 $this->command('optimize:clear');
19 }
20};

#3. Run It

Terminal
php artisan execute
Executing 2026_01_15_120000_warm_caches...

Running the command again does nothing, because a ONCE executor has already run:

There are no executors need to be executed.

#4. Check the Status

Terminal
php artisan execute:status
+-----------------------------------+------+------+---------+-------+----------+
| Name | Type | Tags | Servers | Batch | Executed |
+-----------------------------------+------+------+---------+-------+----------+
| 2026_01_15_120000_warm_caches | Once | None | All | 1 | Yes |
+-----------------------------------+------+------+---------+-------+----------+

#Writing Executors

An executor is a PHP file that returns an instance of an anonymous class extending Pharaonic\Laravel\Executor\Classes\Executor. Files that don't return an executor are skipped.

#Type

$type decides how often the executor runs. It defaults to ExecutorType::ALWAYS.

TypeRuns
ExecutorType::ONCEThe first time php artisan execute sees it, then never again
ExecutorType::ALWAYSEvery time php artisan execute runs
executors/2026_01_15_120000_warm_caches.php
1public $type = ExecutorType::ONCE;

#Tags

$tags groups executors, so you can run only some of them with --tags.

executors/2026_01_15_120000_warm_caches.php
1public $tags = ['cache', 'search'];

#Servers

$servers lists the servers the executor belongs to, by name or by IP address. Leave it empty to run on every server.

executors/2026_01_15_120000_warm_caches.php
1public $servers = ['web-1', 'web-2'];

#Naming Servers

Give each server a fixed name with EXECUTOR_SERVER, and list those names in $servers. Names are the recommended way: they stay the same when a server's address changes, and they read better than addresses.

.env
EXECUTOR_SERVER=web-1

A server matches an entry of $servers when the entry is its EXECUTOR_SERVER name or one of the addresses of its network interfaces, ignoring 127.0.0.1 and ::1. A list can mix both, such as ['web-1', '10.0.0.12']. On the other servers, the executor is skipped and doesn't appear as run.

Docker and Other Containers

Inside a container, the package sees the container's own address, such as 172.17.0.5, not the address of the host, and the address changes when the container is recreated. Host addresses in $servers then never match, and container addresses match only until the next recreate, after which ONCE executors run again. Set EXECUTOR_SERVER in each container's environment and list the names instead.

#Records per Server

An executor with servers keeps one record per server, stored under the first entry of the list that matches the server:

TypeWithout $serversWith $servers
ONCERuns once, on the first server that deploysRuns once on each listed server
ALWAYSRuns on every server, every deployRuns on each listed server, every deploy

Use $servers with ONCE for setup each server needs once, such as linking local storage, and leave $servers empty for work one server does for all of them, such as dispatching a job.

#Changing the List

  • Removing a server: it stops running the executor, and execute:rollback on it leaves the executor alone. Its record stays, so a ONCE executor doesn't run again if you add the server back.
  • Adding a server: it runs the executor on its next deploy.
  • Emptying the list: the servers that already ran a ONCE executor skip it, and the first other server that deploys runs it once for all of them.
  • A server's address changes: a server listed by address counts as a new server and runs its ONCE executors again. A server listed by its EXECUTOR_SERVER name keeps its record.
  • Switching a server from its address to a name: set EXECUTOR_SERVER while the old address is still in the list, deploy once, then replace the address with the name. The record stays under the old address and the server still finds it by that address; it keeps finding it as long as the address doesn't change.
Records From Earlier Releases

A record written before per-server records has no server, so it counts as run on every server and its ONCE executor doesn't run again.

#Running Artisan Commands

$this->command() calls an Artisan command, prints its output, and returns its exit code.

1public function up(): void
2{
3 $this->command('cache:clear');
4 $this->command('queue:restart');
5}

#Dispatching Jobs

$this->job() dispatches a job. Pass the class name and its constructor arguments, or a job instance. It returns Laravel's pending dispatch, so you can chain onQueue(), delay() and the other dispatch options.

1use App\Jobs\RecalculateRatings;
2 
3public function up(): void
4{
5 $this->job(RecalculateRatings::class, 'electronics')->onQueue('ratings');
6 $this->job(new RecalculateRatings('books'))->delay(now()->addMinutes(5));
7}
Closures

job() doesn't accept closures or other callables and throws InvalidArgumentException. Use a job class.

#Writing Output

Executors use Laravel's console output helpers, such as info(), line(), warn(), error() and table().

1public function up(): void
2{
3 $count = Product::query()->whereNull('slug')->count();
4 
5 $this->info("Generating {$count} slugs...");
6}

#Reversing an Executor

down() runs when the executor's batch is rolled back. Leave it empty when there's nothing to undo.

#Validation

The executor checks its properties when it is created and throws InvalidArgumentException when:

  • $type isn't an ExecutorType case;
  • $tags isn't an array;
  • $servers isn't an array.

#Running Executors

php artisan execute reads every executor file, picks the ones that should run, and runs them in file-name order.

Terminal
php artisan execute

An executor runs when it has never run before, or when its type is ALWAYS. Executors limited to other servers are skipped.

#Batches

Every executor that runs for the first time in the same php artisan execute call gets the same batch number, one higher than the highest batch in the table. An ALWAYS executor keeps the batch of its first run; the package counts its runs and stores the time of the last one.

#Several Servers at Once

When servers deploy at the same time, php artisan execute takes a lock, so they run the executors one after another. The next server reads the executors table only after the lock is free, so a ONCE executor that another server just ran is skipped. execute:rollback and execute:fresh take the same lock.

The lock is a reserved row of the executors table, so every server that shares the table shares the lock, without any cache setup. A server that stops while holding it frees it after pharaonic.executor.lock.seconds. The records are read from the write connection, so a read replica that lags behind can't hide a run.

If the lock isn't free within pharaonic.executor.lock.seconds (600 by default), the command fails with exit code 1:

Another server has been running the executors for more than 600 seconds.

If the lock can't be written, for example before php artisan migrate has added the server column, the command stops with exit code 1 before running any executor, and prints the database error.

#Running One Executor

Pass the executor name, which is its file name without .php:

Terminal
php artisan execute 2026_01_15_120000_warm_caches

#Filtering by Tags

--tags takes a comma-separated list and runs the executors that have at least one of the tags:

Terminal
php artisan execute --tags=cache,search

#Starting Over

execute:fresh empties the executors table and runs php artisan execute, so every executor runs again:

Terminal
php artisan execute:fresh
Production

execute:fresh runs every ONCE executor again. Use it in local and testing environments.

#Rolling Back

execute:rollback reverses the latest batch: it calls down() on each executor of the batch and deletes their records, so they run again on the next php artisan execute.

Terminal
php artisan execute:rollback

Roll back several batches with --steps:

Terminal
php artisan execute:rollback --steps=3
Rollbacks per Server

A rollback only touches the records this server sees: the records of executors without $servers, and this server's own records of executors with $servers. It never runs down() for an executor limited to other servers, and it leaves their records for them. To roll back an executor on each of its servers, run execute:rollback on each of them. --steps counts the batches of this server.

Deleted Files

The records of the rolled-back batches are deleted even when an executor file no longer exists; down() only runs for the files that do.

#Status

execute:status lists every executor file with its record:

Terminal
php artisan execute:status
+-----------------------------------+--------+---------------+-----------+-------+----------+
| Name | Type | Tags | Servers | Batch | Executed |
+-----------------------------------+--------+---------------+-----------+-------+----------+
| 2026_01_15_120000_warm_caches | Once | cache, search | 10.0.0.11 | 1 | Yes |
| 2026_01_16_090000_sync_currencies | Always | None | All | N/A | No |
+-----------------------------------+--------+---------------+-----------+-------+----------+
ColumnShows
NameThe file name without .php
TypeOnce or Always
TagsThe executor's tags, or None
ServersThe server names or IP addresses, or All
BatchThe batch of the first run, or N/A when it never ran
ExecutedWhether it has run at least once; for an executor with $servers, whether it has run on this server

The same data is available in code through the facade:

1use Pharaonic\Laravel\Executor\Facades\Executor;
2 
3Executor::info();
4// ['2026_01_15_120000_warm_caches' => ['name' => ..., 'path' => ..., 'type' => ExecutorType::ONCE, 'tags' => ['cache', 'search'], 'servers' => ['10.0.0.11'], 'batch' => 1, 'executed' => true], ...]

#Executor Paths

Executors live in the executors folder of your project. Create one somewhere else with --path, relative to the project root:

Terminal
php artisan make:executor ImportCountries --path=modules/geo/executors

Then register the folder in a service provider, so execute, execute:rollback and execute:status read it too:

app/Providers/AppServiceProvider.php
1use Pharaonic\Laravel\Executor\Facades\Executor;
2 
3public function boot(): void
4{
5 Executor::getPool()->addPath(base_path('modules/geo/executors'));
6}

The package reads the .php files directly inside each folder, not in subfolders.

Unique Names

Executor names must be unique across all folders. Two files with the same name throw LogicException.

#API Reference

#Artisan Commands

CommandDescription
make:executor {name} {--path=}Create an executor in executors, or in --path relative to the project root
execute {name?} {--tags=}Run the executors that should run, optionally one by name or those with one of the tags
execute:rollback {--steps=1}Call down() on the executors of the latest batches and delete their records
execute:freshEmpty the executors table and run execute
execute:statusList every executor with its type, tags, servers, batch and status

#Executor

Pharaonic\Laravel\Executor\Classes\Executor, the class every executor extends.

MemberDescription
public $typeExecutorType::ONCE or ExecutorType::ALWAYS (default)
public $tagsArray of tags, empty by default
public $serversArray of server names (EXECUTOR_SERVER) or IP addresses, empty for every server
up(): voidRuns the task
down(): voidReverses the task on rollback
command(string $command, array $parameters = []): intCalls an Artisan command and returns its exit code
job(string|object $job, mixed ...$arguments): PendingDispatchDispatches a job class with its constructor arguments, or a job instance

#ExecutorType

Pharaonic\Laravel\Executor\Enums\ExecutorType, a backed enum that uses Pharaonic\SmartEnum\SmartEnum.

MemberDescriptionReturns
ExecutorType::ALWAYSRuns on every execute, stored as 1ExecutorType
ExecutorType::ONCERuns a single time, stored as 2ExecutorType
isAlways()Whether the type is ALWAYSbool
isOnce()Whether the type is ONCEbool
label()Always or Oncestring
options()Labels keyed by value: [1 => 'Always', 2 => 'Once']array
names() / values() / labels()Every case name, value or labelarray
fromName() / tryFromName() / hasName()Find a case by name ('ONCE')ExecutorType / ?ExecutorType / bool
hasValue()Whether a case has the valuebool
is() / isNot() / in() / notIn() / eq()Compare with a case, name or valuebool
from() / tryFrom() / cases()PHP's native enum methods

#Facade

Pharaonic\Laravel\Executor\Facades\Executor

MethodDescriptionReturns
getPool()The pool of executor foldersExecutorPool
getRecords()The executor records this server sees, keyed by name: its own record of an executor with $servers, or else the shared recordCollection
getNextBatchNumber()One higher than the highest batchint
getIPs()The server's IP addresses, without 127.0.0.1 and ::1array
getServer()The server's EXECUTOR_SERVER name?string
isServer(string $server)Whether a name or IP address is this serverbool
info()Every executor's name, path, type, tags, servers, batch and status, keyed by namearray

#ExecutorPool

Pharaonic\Laravel\Executor\Classes\ExecutorPool, returned by Executor::getPool().

MethodDescriptionReturns
addPath(string $path)Adds a folder of executorsstatic
getPaths()The executor foldersarray

#Model

Pharaonic\Laravel\Executor\Models\Executor, one record per executor that has run.

AttributeTypeDescription
idintPrimary key
typeExecutorTypeThe executor's type
namestringThe executor's file name without .php
server?stringThe server of the record for an executor with $servers, or null for a shared record; unique together with name
tags?arrayThe executor's tags
servers?arrayThe executor's server names or IP addresses
batchintThe batch of the first run
executedintHow many times it has run
last_executed_at?CarbonInterfaceWhen it last ran
MethodDescriptionReturns
isNew()Whether it has never runbool
isExecutable()Whether its type is ALWAYS or it has never runbool
execute()Counts a run and stores its timevoid

#Publish Tags

TagPublishes
executor-config, pharaonic-configconfig/pharaonic/executor.php
executor-migrations, pharaonic-migrationsThe migration, into database/migrations
laravel-executor, pharaonicBoth

#Examples

#1. Deploy Script

Run the executors on every server after the migrations.

deploy.sh
1php artisan down
2git pull origin main
3composer install --no-dev --optimize-autoloader
4php artisan migrate --force
5php artisan execute
6php artisan up

#2. One-Time Data Fix

Fill a new column once, in chunks, and clear it again on rollback.

executors/2026_02_01_090000_fill_product_slugs.php
1use App\Models\Product;
2use Illuminate\Support\Str;
3use Pharaonic\Laravel\Executor\Classes\Executor;
4use Pharaonic\Laravel\Executor\Enums\ExecutorType;
5 
6return new class () extends Executor {
7 public $type = ExecutorType::ONCE;
8 
9 public function up(): void
10 {
11 Product::query()->whereNull('slug')->chunkById(500, function ($products) {
12 foreach ($products as $product) {
13 $product->update(['slug' => Str::slug($product->name)]);
14 }
15 });
16 }
17 
18 public function down(): void
19 {
20 Product::query()->update(['slug' => null]);
21 }
22};

#3. Caches on Every Deploy

Rebuild the caches on every deploy, on every server.

executors/2026_02_01_090100_rebuild_caches.php
1use Pharaonic\Laravel\Executor\Classes\Executor;
2use Pharaonic\Laravel\Executor\Enums\ExecutorType;
3 
4return new class () extends Executor {
5 public $type = ExecutorType::ALWAYS;
6 
7 public $tags = ['cache'];
8 
9 public function up(): void
10 {
11 $this->command('optimize');
12 $this->command('view:cache');
13 }
14 
15 public function down(): void
16 {
17 $this->command('optimize:clear');
18 }
19};

Rebuild only the caches, without the other executors:

Terminal
php artisan execute --tags=cache

#4. Queue a Job Once

Queue a recalculation once, from whichever server deploys first. The workers pick it up from the shared queue.

executors/2026_02_01_090200_recalculate_ratings.php
1use App\Jobs\RecalculateRatings;
2use Pharaonic\Laravel\Executor\Classes\Executor;
3use Pharaonic\Laravel\Executor\Enums\ExecutorType;
4 
5return new class () extends Executor {
6 public $type = ExecutorType::ONCE;
7 
8 public $tags = ['ratings'];
9 
10 public function up(): void
11 {
12 $this->info('Queueing the rating recalculation...');
13 
14 $this->job(RecalculateRatings::class)->onQueue('ratings');
15 }
16 
17 public function down(): void
18 {
19 //
20 }
21};
app/Jobs/RecalculateRatings.php
1namespace App\Jobs;
2 
3use App\Models\Product;
4use Illuminate\Bus\Queueable;
5use Illuminate\Contracts\Queue\ShouldQueue;
6use Illuminate\Foundation\Bus\Dispatchable;
7use Illuminate\Queue\InteractsWithQueue;
8 
9class RecalculateRatings implements ShouldQueue
10{
11 use Dispatchable, InteractsWithQueue, Queueable;
12 
13 public function handle(): void
14 {
15 Product::query()->chunkById(500, function ($products) {
16 foreach ($products as $product) {
17 $product->update(['rating' => $product->reviews()->avg('stars') ?? 0]);
18 }
19 });
20 }
21}

#5. A Task for Each Web Server

Link the public storage folder once on each web server, because every server has its own disk.

executors/2026_02_01_090300_link_storage.php
1use Pharaonic\Laravel\Executor\Classes\Executor;
2use Pharaonic\Laravel\Executor\Enums\ExecutorType;
3 
4return new class () extends Executor {
5 public $type = ExecutorType::ONCE;
6 
7 public $servers = ['web-1', 'web-2'];
8 
9 public function up(): void
10 {
11 $this->command('storage:link');
12 }
13 
14 public function down(): void
15 {
16 //
17 }
18};

Each web server sets its name with EXECUTOR_SERVER=web-1 or EXECUTOR_SERVER=web-2. Each listed server runs the executor on its first deploy and skips it after that. A server added to the list later runs it on its next deploy.

#Troubleshooting

#"There are no executors need to be executed."

Every ONCE executor has already run and there's no ALWAYS executor. Check the list with php artisan execute:status. If the executor lives outside the executors folder, register its folder with Executor::getPool()->addPath().

#"Undefined constant ExecutorType::Once"

The executor uses a case name from 1.x or 12.0.x. Rename ExecutorType::Always to ExecutorType::ALWAYS and ExecutorType::Once to ExecutorType::ONCE, as described in Upgrading.

#"Class Pharaonic\Laravel\Executor\Executor not found"

The executor still extends the 1.x class. Use Pharaonic\Laravel\Executor\Classes\Executor, rename handle() to up(), and add a down() method, as described in Upgrading.

#"Column not found: name" after upgrading from 1.x

The executors table still has the 1.x shape, and php artisan migrate doesn't change it. Recreate the table and copy its records, as described in Upgrading.

#"Another server has been running the executors for more than 600 seconds."

Another php artisan execute, execute:rollback or execute:fresh holds the lock: a deploy is still running, or a run stopped before releasing it and the lock hasn't expired yet. Wait for the other deploy, or raise EXECUTOR_LOCK_SECONDS when your executors take longer than 600 seconds.

#"Couldn't take the executor lock: …"

The command couldn't write the lock row to the executors table, so it stopped before running anything. The message ends with the database error. Run php artisan migrate, which adds the server column the lock needs, and check that EXECUTOR_CONNECTION reaches the database.

#A ONCE executor ran on two servers

When the executor has $servers, it runs once on each listed server; leave $servers empty to run it once for all of them. Otherwise the servers don't share the executors table: point EXECUTOR_CONNECTION at a connection every server uses.

#An executor doesn't appear in execute:status

The file must be directly inside an executor folder, end in .php, and return the executor instance (return new class () extends Executor { ... };). Files that return anything else are skipped.

#"Duplicate Executor name"

Two folders contain a file with the same name. Rename one of them, keeping its timestamp prefix.

#"The type of the executor must be an instance of ExecutorType."

$type holds something other than a case, such as 1 or 'once'. Use ExecutorType::ONCE or ExecutorType::ALWAYS.

#An executor runs on the wrong server

$servers is compared with the server's EXECUTOR_SERVER name and the addresses of its network interfaces. Behind NAT or a load balancer, use the server's private address; inside Docker or another container, the package sees the container's address, so set EXECUTOR_SERVER and list names instead. Check what the package sees with php artisan tinker, Executor::getServer() and Executor::getIPs().

#execute:make prints a deprecation notice

The command was renamed. Use php artisan make:executor.

Contributors

Amazing people who made this package possible

This package wouldn't exist without the contributions of our amazing community. A huge thank you to everyone who has helped improve Executor!

Moamen Eltouny

@MoamenEltouny

146 contributions

Karim Mohamed

@komtcho

11 contributions

Moemen Gaballah

@Moemen-Gaballah

3 contributions

Elsayed Elbeshry

@Elsayed93

1 contribution

Want to Contribute?

We welcome contributions from everyone! Whether it's bug fixes, new features, or documentation improvements - every contribution counts.