PHPackages                             moderntribe/square1-queues - 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. moderntribe/square1-queues

ActiveLibrary

moderntribe/square1-queues
==========================

A queues provider for square one

4.2.3(5mo ago)05.1k12GPL-2.0-onlyPHPPHP &gt;=7.4

Since Jul 3Pushed 5mo ago19 watchersCompare

[ Source](https://github.com/moderntribe/square1-queues)[ Packagist](https://packagist.org/packages/moderntribe/square1-queues)[ RSS](/packages/moderntribe-square1-queues/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (46)Used By (2)

Queues
======

[](#queues)

The Queue library provides a utility for background processing of potentially slow, time consuming, or network-dependent tasks.

Configure queues with the MySQL Backend
---------------------------------------

[](#configure-queues-with-the-mysql-backend)

Include [Queue\_Definer](https://github.com/moderntribe/tribe-libs/blob/master/src/Queues/Queues_Definer.php), [Queue\_Subscriber](https://github.com/moderntribe/tribe-libs/blob/master/src/Queues/Queues_Subscriber.php) and the [Mysql\_Backend\_Definer](https://github.com/moderntribe/tribe-libs/blob/master/src/Queues_Mysql/Mysql_Backend_Definer.php), [Mysql\_Backend\_Subscriber](https://github.com/moderntribe/tribe-libs/blob/master/src/Queues_Mysql/Mysql_Backend_Subscriber.php) in your [Core.php](https://github.com/moderntribe/square-one/blob/main/wp-content/plugins/core/src/Core.php), **ensuring to add the MySQL providers items *after* the Queue providers.**

Run the following to create the queues database table:

```
wp s1 queues add-table
```

Getting the Queue Object
------------------------

[](#getting-the-queue-object)

While it is possible (and in rare cases appropriate) to have multiple queues, most often a project will use a single default queue. Using the DI container, your class constructor should receive a `\Tribe\Libs\Queues\Contracts\Queue`. Autowiring should take care of the rest to give you an instance of the appropriate queue class with the configured backend.

```
class Example_Class {
  private $queue;
  public function __construct( \Tribe\Libs\Queues\Contracts\Queue $queue ) {
    $this->queue = $queue;
  }
}
```

Creating a task handler
-----------------------

[](#creating-a-task-handler)

If you are putting things into queue, it is very likely you will need to create a custom task handler. To create a Task class, implement `Tribe\Project\Queues\Contracts\Task`.

The `handle( array $args )` method is required and must return `true` on success (the task is marked as complete and removed from the queue), `false` on failure (the task is added back into the queue to try again).

The task handler instance is run in isolation, but still supports auto wiring and dependency injection.

Example Task:

```
