PHPackages                             masnun/joinjobs - 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. masnun/joinjobs

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

masnun/joinjobs
===============

A Laravel package that allows scheduling certain actions upon job completion or queue exhaustion.

352PHP

Since Nov 25Pushed 11y ago1 watchersCompare

[ Source](https://github.com/masnun/laravel-joinjobs)[ Packagist](https://packagist.org/packages/masnun/joinjobs)[ RSS](/packages/masnun-joinjobs/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Join Jobs
-----------------

[](#laravel-join-jobs)

A Laravel package that allows scheduling certain actions upon job completion or queue exhaustion.

This package allows you to register a class or closure to be executed when an individual job completes. You can also register a class or closure when each and every job from a batch of jobs has finished running.

**The package was sponsored by the good people at Pure SEO**

### Installation

[](#installation)

The package is available from the Packagist composer repository. Add these to your `composer.json` file and run `composer install`:

```
"masnun/joinjobs": "dev-master"
```

### Registering the Service Provider

[](#registering-the-service-provider)

Once you have installed the package, you need to register the service provider. Open `app/config/app.php` and add `Masnun\Joinjobs\JoinjobsServiceProvider` to the `providers` array.

### Other relevant Configurations

[](#other-relevant-configurations)

- You must make sure that Laravel has an active database connection properly configured.
- To test the queues, you need to configure Laravel queues properly. Use an async queue for the best results.

Please consult the appropriate sections of the Laravel Docs to set them up properly.

### Running The Migrations

[](#running-the-migrations)

The package uses certain database tables to keep track of jobs and queues. We need to run the migrations on the package to make sure the database schema is created properly.

```
php artisan migrate --package=masnun/joinjobs
```

### Using the API

[](#using-the-api)

The process is simple:

- Create a new join, pass it a handler. Choose whether it should be auto deleted or not. The handler could be a closure or fully qualified class name that has a `run()` method. The second parameter is for auto deletion.
- We add jobs to the Join. Each job can take an optional closure/class to be executed.
- We have to let the system know when all jobs have been dispatched. We can pass the optional 3rd argument to a job as `true` to mark it as the last job. Or alternatively we can call the `setFullyDispatched($joinId)` method on the JoinJobsManager.

    Eg. `$joinjobsManager->setFullyDispatched($joinId)`

    This is a requirement to make sure that our JoinHandler is not executed before all jobs have been dispatched while using a `sync` driver.

#### Creating a new Join and adding jobs to it

[](#creating-a-new-join-and-adding-jobs-to-it)

```

 	 // Create a new manager
    $joinjobsManager = new JoinJobsManager();

    // We create a new join, set auto deletion to true
    $joinId = $joinjobsManager->createJoin(null, true);

    $joinjobsManager->addHandlerToJoin($joinId, function() {
            echo "The Join successfully completed!";
    });

    // addJob()
    $jobId = $joinjobsManager->addJob($joinId);

    Queue::push('DemoJob', ['jobId' => $jobId, 'sleepDuration' => 5]);

    $joinjobsManager->addHandlerToJob($jobId, function() use($jobId) {
            echo "Completed Job ID: {$jobId}";
    });

	// This job is the last one, we are not adding any more jobs
    $jobId = $joinjobsManager->addJob($joinId, "\\Masnun\\Joinjobs\\JoinHandler", true);
    Queue::push('DemoJob', ['jobId' => $jobId, 'sleepDuration' => 10]);

    return "Added two jobs!";
```

#### Marking a Job Complete

[](#marking-a-job-complete)

Once a job is complete, we must let our `JoinJobsManager` know that one of the job has finished executing. Here's a sample `DemoJob` class:

```
class DemoJob
{
    public function fire($job, $data)
    {
        // We could put this in the DI containter
        // if we use this a lot
        $joinjobsManager = new JoinJobsManager();

        $jobId = $data['jobId'];
        $sleepDuration = $data['sleepDuration'];

        sleep($sleepDuration);

        // Mark the job as complete
        $joinjobsManager->completeJob($jobId);

		// Remove the job from Queue
        $job->delete();
    }
}
```

#### Auto Deletion

[](#auto-deletion)

The `createJoin()` method takes a second optional argument. If we set it true, the join and all jobs related to it will be deleted.

#### Manual Deletion

[](#manual-deletion)

```
$joinjobsManager->deleteJoin($joinId);

```

That should delete the join and all the jobs belonging to it.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/821e866ed5dfded4927a03317283a3d747b379da4d9f615b747982a2753439e0?d=identicon)[masnun](/maintainers/masnun)

---

Top Contributors

[![masnun](https://avatars.githubusercontent.com/u/191543?v=4)](https://github.com/masnun "masnun (12 commits)")

### Embed Badge

![Health badge](/badges/masnun-joinjobs/health.svg)

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

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[amphp/parser

A generator parser to make streaming parsers simple.

14952.8M16](/packages/amphp-parser)[amphp/serialization

Serialization tools for IPC and data storage in PHP.

13451.1M18](/packages/amphp-serialization)[enqueue/enqueue

Message Queue Library

19820.0M56](/packages/enqueue-enqueue)[deliciousbrains/wp-background-processing

WP Background Processing can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.

1.1k409.8k6](/packages/deliciousbrains-wp-background-processing)[react/async

Async utilities and fibers for ReactPHP

2238.8M170](/packages/react-async)

PHPackages © 2026

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