PHPackages                             bytetcore/queue-unique-runner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. bytetcore/queue-unique-runner

ActiveLibrary[Queues &amp; Workers](/categories/queues)

bytetcore/queue-unique-runner
=============================

Ensure Laravel queue jobs run on only one server instance at a time with database or Redis distributed locking, heartbeat, and crash recovery.

1.0.0(today)01↑2900%Apache-2.0PHPPHP ^8.0CI passing

Since Apr 3Pushed todayCompare

[ Source](https://github.com/ByteTCore/queue-unique-runner)[ Packagist](https://packagist.org/packages/bytetcore/queue-unique-runner)[ RSS](/packages/bytetcore-queue-unique-runner/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

bytetcore/queue-unique-runner
=============================

[](#bytetcorequeue-unique-runner)

Ensure your Laravel queue jobs run on only **one server instance at a time** using distributed locking. Includes automatic crash recovery, lock heartbeat, and supports both Database and Redis drivers.

[![Tests](https://github.com/bytetcore/queue-unique-runner/actions/workflows/tests.yml/badge.svg)](https://github.com/bytetcore/queue-unique-runner/actions/workflows/tests.yml)[![License](https://camo.githubusercontent.com/a549a7a30bacba7bfceebdc207a8e86c3f2c02995a2527640dca30048fd2b64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c75652e737667)](https://opensource.org/licenses/Apache-2.0)

The Problem
-----------

[](#the-problem)

When running multiple queue workers across different servers, sometimes you have jobs that **must not run concurrently** under any circumstances (e.g., end-of-day financial calculations, syncing large datasets with third-party APIs).

While Laravel's `WithoutOverlapping` middleware is great, if a server crashes midway through a job, the lock gets permanently stuck until manually cleared.

The Solution
------------

[](#the-solution)

`queue-unique-runner` provides robust distributed locking with:

- **Heartbeat mechanism:** Periodically extends the lock while the job is actively running.
- **Crash recovery:** If a server crashes or the worker is abruptly killed, the heartbeat stops, the lock expires automatically via TTL, and another server can safely retry the job.
- **Per-class or Per-instance locking:** Lock the entire job class, or lock per unique payload.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require bytetcore/queue-unique-runner
```

**If using the Database driver** (the default), publish and run the migrations:

```
php artisan vendor:publish --tag="queue-unique-runner-migrations"
php artisan migrate
```

Optionally, publish the config file:

```
php artisan vendor:publish --tag="queue-unique-runner-config"
```

Usage
-----

[](#usage)

Simply add the `RunsOnUniqueRunner` trait to your job:

```
namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Bytetcore\QueueUniqueRunner\Traits\RunsOnUniqueRunner;

class ProcessFinancialAudit implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    use RunsOnUniqueRunner; // userId = $userId;
    }

    // Lock scope: 'class' (only one SyncUserData job anywhere)
    // or 'instance' (one SyncUserData job per unique payload)
    public function queueUniqueRunnerScope(): string
    {
        return 'instance';
    }

    // Custom identifier for 'instance' scope
    public function queueUniqueRunnerIdentifier(): ?string
    {
        return 'user:' . $this->userId;
    }

    // How long the lock should be held (in seconds)
    public function queueUniqueRunnerTtl(): int
    {
        return 600; // 10 minutes
    }

    // How long to wait before retrying if another server holds the lock
    public function queueUniqueRunnerRetryDelay(): int
    {
        return 60; // Wait 60 seconds
    }
}
```

Drivers
-------

[](#drivers)

### Database (Default)

[](#database-default)

Creates a `queue_unique_runner_locks` table. Uses unique constraints to guarantee atomic locks.

It is recommended to periodically run the prune command to clean up expired locks from the database:

```
# Add this to your Console/Kernel.php schedule
$schedule->command('queue-unique-runner:prune')->daily();
```

### Redis

[](#redis)

Uses `SET NX EX` commands and Lua scripts for atomic operations. Extremely fast and automatically handles expired lock cleanup.

Change your `.env`:

```
SINGLE_JOB_DRIVER=redis
SINGLE_JOB_REDIS_CONNECTION=default
```

Requirements
------------

[](#requirements)

- PHP 8.0+
- Laravel 9.0+
- (Optional but recommended) `pcntl` extension for Heartbeat functionality

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

38

—

LowBetter than 84% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3be00157eb3b2afdf3024f93dcbe423e0fc71180431eccf5e48fe73f4d71d40d?d=identicon)[dovutuan](/maintainers/dovutuan)

---

Top Contributors

[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelmutexqueuejobheartbeatdistributed-lockunique-runnercrash-recovery

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/bytetcore-queue-unique-runner/health.svg)

```
[![Health](https://phpackages.com/badges/bytetcore-queue-unique-runner/health.svg)](https://phpackages.com/packages/bytetcore-queue-unique-runner)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M200](/packages/laravel-horizon)[imtigger/laravel-job-status

Laravel Job Status

5272.1M2](/packages/imtigger-laravel-job-status)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

3786.5k](/packages/harris21-laravel-fuse)[maqe/laravel-sqs-fifo

Laravel package that enables support for SQS FIFO Queue

15137.2k](/packages/maqe-laravel-sqs-fifo)[pmatseykanets/artisan-beans

Easily manage your Beanstalkd job queues right from the Laravel artisan command

4482.1k](/packages/pmatseykanets-artisan-beans)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
