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

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

openclerk/jobs
==============

Simple PHP job queueing, execution and management

0.1.0(8y ago)21591PHP

Since Sep 11Pushed 8y ago2 watchersCompare

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

READMEChangelogDependencies (5)Versions (2)Used By (0)

openclerk/jobs [![Build Status](https://camo.githubusercontent.com/e55268d79d5cb160e4d520a5fa5819a56be41327bc6e3d6744dab93578f665ec/68747470733a2f2f7472617669732d63692e6f72672f6f70656e636c65726b2f6a6f62732e737667)](https://travis-ci.org/openclerk/jobs)
============================================================================================================================================================================================================================================================

[](#openclerkjobs-)

A library for simple PHP job queueing, execution and management, used by [Openclerk](http://openclerk.org) and live on [CryptFolio](https://cryptfolio.com).

While cron jobs are a simple approach to running regular tasks, `openclerk/jobs` allows tasks to be defined, executed and managed in reliable ways.

Installing
----------

[](#installing)

Include `openclerk/jobs` as a requirement in your project `composer.json`, and run `composer update` to install it into your project:

```
{
  "require": {
    "openclerk/jobs": "dev-master"
  }
}
```

Features
--------

[](#features)

1. Queue up jobs immediately for execution later
2. Jobs can return success or failure (by throwing exceptions)
3. Repeatedly failing jobs can be removed from the job execution queue
4. Define your own job selection algorithms
5. Any exceptions thrown during job execution are stored in the `job_exceptions` table

Using
-----

[](#using)

### Define a job class

[](#define-a-job-class)

```
use \Openclerk\Jobs\Job;
use \Db\Connection;
use \Monolog\Logger;

class MyJob implements Job {

  /**
   * @param $job the `job` instance, an array of `job_type`, `arg_id` and optionally `user_id`
   */
  function __construct($job) {
    $this->job = $job;
  }

  function run(Connection $db, Logger $logger) {
    $q = $db->prepare("SELECT * FROM table WHERE id=?");
    $q->execute(array($this->job['arg_id']));
    if (!$q->fetch()) {
      throw new \Exception("Could not find that instance");
    }
  }

  function passed(Connection $db, Logger $logger) {
    // (optional) the job passed
  }

  function failed(\Exception $runtime_exception, Connection $db, Logger $logger) {
    // (optional) the job failed
  }
}
```

### Define a job queuer

[](#define-a-job-queuer)

```
use \Openclerk\Jobs\JobQueuer;
use \Openclerk\Jobs\Job;
use \Db\Connection;
use \Monolog\Logger;

class MyJobQueuer extends JobQueuer {

  /**
   * Get a list of all jobs that need to be queued, as an array of associative
   * arrays with (job_type, arg_id, [user_id]).
   */
  function findJobs(Connection $db, Logger $logger) {
    $result = array();

    $q = $db->prepare("SELECT * FROM table WHERE is_queued=0");
    $q->execute();
    while ($r = $q->fetch()) {
      $result[] = array(
        'job_type' => 'table',
        'arg_id' => $r['id'],
        // optional: user_id
      );
    }

    return $result;
  }

  /**
   * The given job has been queued up, so we can mark it as successfully queued.
   */
  function jobQueued(Connection $db, Logger $logger, $job) {
    $q = $db->prepare("UPDATE table SET is_queued=1 WHERE id=?");
    $q->execute(array($job['arg_id']));
  }
}
```

### Define a job runner

[](#define-a-job-runner)

```
use \Openclerk\Jobs\JobRunner;
use \Openclerk\Jobs\Job;
use \Db\Connection;
use \Monolog\Logger;

class MyJobRunner extends JobRunner {

  /**
   * Get the {@link Job} to run for this job type.
   */
  function createJob($job, Connection $db, Logger $logger) {
    switch ($job['job_type']) {
      case 'table':
        return new MyJob($job);
    }
  }

}
```

### Write batch scripts to execute the queuer and runner

[](#write-batch-scripts-to-execute-the-queuer-and-runner)

For example, a batch script to queue up new jobs:

```
$logger = new \Monolog\Logger("batch_queue");
$logger->pushHandler(new \Core\MyLogger());

$runner = new MyJobQueuer();
$runner->queue(db(), $logger);
```

Or, a batch script to run a single job:

```
$logger = new \Monolog\Logger("batch_run");
$logger->pushHandler(new \Core\MyLogger());

$runner = new MyJobRunner();
$runner->runOne(db(), $logger);
```

These batch scripts can then be setup with cron, etc.

Extensions
----------

[](#extensions)

1. [Using `require()` for running jobs instead of classes](https://github.com/soundasleep/openclerk/blob/master/core/GenericOpenclerkJob.php)
2. [Run jobs only of a certain type](https://github.com/soundasleep/openclerk/blob/master/batch/batch_run_type.php)
3. [Run jobs only of users with particular properties](https://github.com/soundasleep/openclerk/blob/master/batch/batch_run_premium.php)
4. [Run jobs only with a particular job ID](https://github.com/soundasleep/openclerk/blob/master/core/OpenclerkJobRunner.php)
5. [Run jobs from a web admin interface](https://github.com/soundasleep/openclerk/blob/master/pages/admin_run_job.php)

Donate
------

[](#donate)

[Donations are appreciated](https://code.google.com/p/openclerk/wiki/Donating).

TODO
----

[](#todo)

1. Capture jobs that timeout
2. job\_failed events through openclerk/events
3. More tests

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

3170d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ebbec5ccc867054461adebb7c5b6312f8256f989ef96b124892e6e89724afdb?d=identicon)[soundasleep](/maintainers/soundasleep)

---

Top Contributors

[![soundasleep](https://avatars.githubusercontent.com/u/3889656?v=4)](https://github.com/soundasleep "soundasleep (14 commits)")

### Embed Badge

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

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

###  Alternatives

[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

53541.0k3](/packages/jolicode-castor)[coderkungfu/php-queue

A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners.

664129.9k2](/packages/coderkungfu-php-queue)[amphp/cluster

Building multi-core network applications with PHP.

6224.8k1](/packages/amphp-cluster)[neighborhoods/kojo

Neighborhoods Kōjō is a distributed task manager.

1520.6k2](/packages/neighborhoods-kojo)[sweatshop/sweatshop

Abstraction layer for message brokers and job servers, including process management

1112.3k](/packages/sweatshop-sweatshop)[haozu/delay-queue

Delay queue based on redis

123.4k](/packages/haozu-delay-queue)

PHPackages © 2026

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