DatabaseQueue
class DatabaseQueue implements ReliableQueueInterface, QueueGarbageCollectionInterface (View source)
Default queue implementation.
Traits
Provides dependency injection friendly methods for serialization.
Constants
| TABLE_NAME |
The database table name. |
Properties
| protected array | $_serviceIds | An array of service IDs keyed by property name used for serialization. |
from DependencySerializationTrait |
| protected array | $_entityStorages | An array of entity type IDs keyed by the property name of their storages. |
from DependencySerializationTrait |
| protected string | $name | The name of the queue this instance is working with. |
|
| protected Connection | $connection | The database connection. |
Methods
Constructs a \Drupal\Core\Queue\DatabaseQueue object.
Adds a queue item and store it directly to the queue.
Adds a queue item and store it directly to the queue.
Retrieves the number of items in the queue.
Claims an item in the queue for processing.
Releases an item that the worker could not process.
Deletes a finished item from the queue.
Creates a queue.
Deletes a queue and every item in the queue.
Cleans queues of garbage.
Check if the table exists and create it if not.
Defines the schema for the queue table.
Details
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
__construct(string $name, Connection $connection)
Constructs a \Drupal\Core\Queue\DatabaseQueue object.
A
createItem($data)
Adds a queue item and store it directly to the queue.
protected A
doCreateItem($data)
Adds a queue item and store it directly to the queue.
int
numberOfItems()
Retrieves the number of items in the queue.
This is intended to provide a "best guess" count of the number of items in the queue. Depending on the implementation and the setup, the accuracy of the results of this function may vary.
e.g. On a busy system with a large number of consumers and items, the result might only be valid for a fraction of a second and not provide an accurate representation.
On
claimItem($lease_time = 30)
Claims an item in the queue for processing.
bool
releaseItem($item)
Releases an item that the worker could not process.
Another worker can come in and process it before the timeout expires.
deleteItem($item)
Deletes a finished item from the queue.
createQueue()
Creates a queue.
Called during installation and should be used to perform any necessary initialization operations. This should not be confused with the constructor for these objects, which is called every time an object is instantiated to operate on a queue. This operation is only needed the first time a given queue is going to be initialized (for example, to make a new database table or directory to hold tasks for the queue -- it depends on the queue implementation if this is necessary at all).
deleteQueue()
Deletes a queue and every item in the queue.
garbageCollection()
Cleans queues of garbage.
protected
ensureTableExists()
Check if the table exists and create it if not.
protected
catchException(Exception $e)
Act on an exception when queue might be stale.
If the table does not yet exist, that's fine, but if the table exists and yet the query failed, then the queue is stale and the exception needs to propagate.
schemaDefinition()
| internal |
Defines the schema for the queue table.