PHPackages                             agatanga/relay - 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. agatanga/relay

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

agatanga/relay
==============

A better way to create complex batch job queues in Laravel.

1.2.3(11mo ago)1136MITPHPPHP ^8.0

Since Jan 21Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/agatanga/relay)[ Packagist](https://packagist.org/packages/agatanga/relay)[ Docs](https://github.com/agatanga/relay)[ RSS](/packages/agatanga-relay/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (3)Versions (7)Used By (0)

Relay
=====

[](#relay)

A better way to create and manage complex batch job queues in Laravel:

```
Relay::chain([new Job1, new Job2])
    ->batch([new Job3_1, new Job3_2])
    ->chain([new Job4, new Job5])
    ->through([new Middleware])
    ->dispatch();
```

**Main features**

- Relay doesn't create/modify DB tables
- Clean looking complex batches
- Ability to set middleware for multiple jobs
- Search for specific batch via metadata
- Monitor batch progress
- Search for failed jobs

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

[](#installation)

```
composer require agatanga/relay
```

Usage Examples
--------------

[](#usage-examples)

### Flatten nested callbacks

[](#flatten-nested-callbacks)

Here is a flattened batches written with Relay:

```
use Agatanga\Relay\Facades\Relay;

Relay::chain('Downloading', [
        new DownloadSources($project),
        new DetectSettings($project),
    ])
    ->then('Updating project data', [
        new ReadStringFiles($project),
        new ReadSourceFiles($project),
    ])
    ->then('Updating project data', [
        new FixFalseUnusedStrings($project),
    ])
    ->finally('Cleaning up', [
        new IgnoreKnownStrings($project),
        new RemoveSources($project),
    ])
    ->through(new Middleware($project))
    ->dispatch();
```

 View the same code written without Relay```
Bus::batch([
    [
        new DownloadSources($project)->through(new Middleware($project)),
        new DetectSettings($project)->through(new Middleware($project)),
    ],
])->then(function (Batch $batch) use ($project) {
    Bus::batch([
        new ReadStringFiles($project)->through(new Middleware($project)),
        new ReadSourceFiles($project)->through(new Middleware($project)),
    ])->then(function (Batch $batch) use ($project) {
        Bus::batch([
            new FixFalseUnusedStrings($project)->through(new Middleware($project)),
        ])->finally(function (Batch $batch) use ($project) {
            Bus::batch([
                new IgnoreKnownStrings($project)->through(new Middleware($project)),
                new RemoveSources($project)->through(new Middleware($project)),
            ])->name('Cleaning up')->dispatch();
        })->name('Updating project data')->dispatch();
    })->name('Updating project data')->dispatch();
})->name('Downloading')->dispatch();
```

### Middleware

[](#middleware)

Relay allows you to set middleware for multiple jobs:

```
Relay::chain([new Job1, new Job2])
    ->batch([new Job3_1, new Job3_2])
    ->chain([new Job4, new Job5], [new Middleware1])
    ->chain([new Job6, new Job7])
    ->through([new Middleware2]) // middleware for Job1-3, Job6-7
    ->dispatch();
```

### Metadata

[](#metadata)

Before we start, you may want to know that Relay doesn't modify `job_batches` table to store metadata. All data is stored inside the `name` column and limited to 255 chars. Here is how the name of the batch may look like with the metadata:

```
Cleaning up|[project:58][project.update:58][3/3]

```

Now, let's see how to use `meta` method to store additional information:

```
use Agatanga\Relay\Facades\Relay;

Relay::chain([
        new DownloadSources($project),
        new DetectSettings($project),
    ])
    ->then([
        new ReadStringFiles($project),
        new ReadSourceFiles($project),
    ])
    ->finally([
        new IgnoreKnownStrings($project),
        new RemoveSources($project),
    ])
    ->name('Update Project (:current of :total)')
    ->meta('project.update', $project->id)
    ->meta('causer', auth()->user()->id)
    ->dispatch();
```

Then search for the batch and retrieve metadata value or name of the batch:

```
use Agatanga\Relay\Facades\Relay;

Relay::whereMeta('causer', $userId)->all();
Relay::whereMeta('project', $id)->first()->meta('causer');
Relay::whereMeta('project.update', $id)->first()->name; // returns clean name
```

### Progress

[](#progress)

Let's assume that the search query from the section above returned the first batch (`then` and `finally` callbacks are not yet started). Relay takes this into account and will return the progress within `0-33%` range.

```
use Agatanga\Relay\Facades\Relay;

Relay::whereMeta('project.update', $id)->first()->progress; // only the last callback can return 100%
```

### Failed Jobs

[](#failed-jobs)

When batch job fails, Laravel adds a failed job record to the `failed_jobs` table.

Relay allows you to retrieve these failed jobs:

```
use Agatanga\Relay\Facades\Relay;

Relay::whereMeta('project.update', $id)->first()->failedJobs();

// or get the exception string of the last failed job

$batch = Relay::whereMeta('project.update', $id)->first();

if ($batch->failed) {
    echo $batch->exception;
}
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance50

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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

Every ~243 days

Recently: every ~302 days

Total

6

Last Release

351d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1108bccc259ec1b0fc93f04a182965faf1213460894ee297f1acf3482e3296ac?d=identicon)[vovayatsyuk](/maintainers/vovayatsyuk)

---

Top Contributors

[![vovayatsyuk](https://avatars.githubusercontent.com/u/306080?v=4)](https://github.com/vovayatsyuk "vovayatsyuk (54 commits)")

---

Tags

laravellaravel-packagelaravel-queueslaravelqueuequeue manager

### Embed Badge

![Health badge](/badges/agatanga-relay/health.svg)

```
[![Health](https://phpackages.com/badges/agatanga-relay/health.svg)](https://phpackages.com/packages/agatanga-relay)
```

###  Alternatives

[mpbarlow/laravel-queue-debouncer

A wrapper job for debouncing other queue jobs.

63714.4k1](/packages/mpbarlow-laravel-queue-debouncer)[harris21/laravel-fuse

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

3786.5k](/packages/harris21-laravel-fuse)[pierophp/laravel-queue-manager

Laravel Queue Manager

182.4k](/packages/pierophp-laravel-queue-manager)

PHPackages © 2026

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