PHPackages                             laratusk/shared-jobs - 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. laratusk/shared-jobs

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

laratusk/shared-jobs
====================

Cross-application job dispatch via shared database for Laravel

v0.1.0(2mo ago)033↓100%MITPHPPHP ^8.2CI passing

Since Mar 11Pushed 2mo agoCompare

[ Source](https://github.com/laratusk/shared-jobs)[ Packagist](https://packagist.org/packages/laratusk/shared-jobs)[ RSS](/packages/laratusk-shared-jobs/feed)WikiDiscussions main Synced 1mo ago

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

Shared Jobs for Laravel
=======================

[](#shared-jobs-for-laravel)

Cross-application job dispatch via a shared database for Laravel. Two separate Laravel apps that connect to the same database can communicate through Laravel's native `database` queue driver and event system.

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

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12
- A shared database accessible by both applications

> This package uses Laravel's `database` queue driver. Both applications must connect to the same database so they can read/write from the shared jobs table.

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

[](#installation)

```
composer require laratusk/shared-jobs
```

Publish and run the migrations:

```
php artisan vendor:publish --tag=shared-jobs-migrations
php artisan migrate
```

Optionally, publish the config file to customize defaults:

```
php artisan vendor:publish --tag=shared-jobs-config
```

Configuration
-------------

[](#configuration)

The package works out of the box with sensible defaults. You only need to set environment variables if you want to customize the behavior:

VariableDefaultDescription`SHARED_JOBS_ROLE``both``dispatcher`, `consumer`, or `both``SHARED_JOBS_CONNECTION``shared-jobs`Queue connection name`SHARED_JOBS_QUEUE``shared`Queue name`SHARED_JOBS_TABLE``shared_jobs`Jobs table name`SHARED_JOBS_DB_CONNECTION``null`Database connection (default connection)`SHARED_JOBS_TRIES``3`Max job attempts`SHARED_JOBS_RETRY_AFTER``90`Retry after seconds`SHARED_JOBS_BACKOFF``0`Backoff seconds`SHARED_JOBS_WAIT_TIMEOUT``30`dispatchAndWait timeout`SHARED_JOBS_WAIT_POLL_INTERVAL``500`Poll interval in msUsage
-----

[](#usage)

### Dispatching Jobs (App 1)

[](#dispatching-jobs-app-1)

```
use Laratusk\SharedJobs\Facades\SharedJob;

SharedJob::dispatch('refund', ['account_id' => 5]);
```

### Consuming Jobs (App 2)

[](#consuming-jobs-app-2)

Start the worker (should be managed by [Supervisor](https://laravel.com/docs/queues#supervisor-configuration) in production):

```
php artisan queue:work shared-jobs --queue=shared
```

Create a listener that extends the base `SharedJobListener`. Laravel's auto-discovery will register it automatically:

```
use Laratusk\SharedJobs\Events\SharedJobReceived;
use Laratusk\SharedJobs\Listeners\SharedJobListener;

class HandleRefund extends SharedJobListener
{
    protected string $jobName = 'refund';

    public function process(array $payload, SharedJobReceived $event): void
    {
        // Handle the refund...
    }
}
```

Alternatively, you can listen for `SharedJobReceived` directly with a plain listener:

```
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Events\Attribute\AsListener;
use Laratusk\SharedJobs\Events\SharedJobReceived;

#[AsListener(SharedJobReceived::class)]
class HandleRefund
{
    public function handle(SharedJobReceived $event): void
    {
        if ($event->name !== 'refund') {
            return;
        }

        // Handle the refund using $event->payload ...
    }
}
```

### Dispatch and Wait

[](#dispatch-and-wait)

For synchronous-like communication:

```
$result = SharedJob::dispatchAndWait('refund', ['account_id' => 5], timeout: 30);
```

In the consumer, respond with data:

```
public function process(array $payload, SharedJobReceived $event): void
{
    // Process...
    $event->respond(['success' => true, 'refund_id' => 123]);
}
```

### Testing

[](#testing)

```
use Laratusk\SharedJobs\Facades\SharedJob;

SharedJob::fake();

// ... code that dispatches ...

SharedJob::assertDispatched('refund', function (string $name, array $payload): bool {
    return $payload['account_id'] === 5;
});

SharedJob::assertNotDispatched('suspend-account');
SharedJob::assertNothingDispatched();
SharedJob::assertDispatchedTimes('refund', 2);
```

How It Works
------------

[](#how-it-works)

```
App 1                        Shared DB                   App 2
─────                        ─────────                   ─────
SharedJob::dispatch(     →   shared_jobs table      →    php artisan queue:work
  'refund',                  (Laravel's own               shared-jobs --queue=shared
  ['account_id' => 5]       jobs table structure)
)                                                         ↓
                                                   ProcessSharedJob::handle()
                                                         ↓
                                                   event(new SharedJobReceived(...))
                                                         ↓
                                                   Your Listener handles it

```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance88

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

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

60d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/755245aa5e4ba6c690b039cedcce5a86cd01b4f00d490cd71f03e6377ac302d5?d=identicon)[laratusk](/maintainers/laratusk)

---

Top Contributors

[![azer1ghost](https://avatars.githubusercontent.com/u/27803185?v=4)](https://github.com/azer1ghost "azer1ghost (3 commits)")

---

Tags

laravelqueuejobsdispatchsharedcross-app

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/laratusk-shared-jobs/health.svg)

```
[![Health](https://phpackages.com/badges/laratusk-shared-jobs/health.svg)](https://phpackages.com/packages/laratusk-shared-jobs)
```

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[harris21/laravel-fuse

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

3786.5k](/packages/harris21-laravel-fuse)[croustibat/filament-jobs-monitor

Background Jobs monitoring like Horizon for all drivers for FilamentPHP

254255.2k6](/packages/croustibat-filament-jobs-monitor)

PHPackages © 2026

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