class Queue extends Model

Implements features of the Queue class.

Constants

BLACKLIST

Constant for blacklist

WHITELIST

Constant for whitelist

Properties

static protected DB $_db

The instance of the DB class.

from  Model
int $id

ID for item in queue.

protected string $_modelName

The name of the model.

from  Model
static protected bool $_softDelete

$_softDelete value.

from  Model
static protected string $_table

Name of the table.

protected bool $_validates

Flag to indicate if validation is successful.

from  Model
protected array $_validationErrors

The array of validation errors.

from  Model
int $attempts

Number of attempts.

$available_at

Available at.

$created_at

Created at.

$exception Exceptions
$failed_at

Failed at.

string $queue

Name of queue.

$reserved_at

Reserved at.

$payload Payload
$updated_at

Updated at.

Methods

__construct()

Default constructor.

from  Model
void
addErrorMessage(string $field, string $message)

Generates error messages that occur during form validation.

from  Model
void
afterDelete()

Called before delete.

from  Model
void
afterSave()

Called before save.

from  Model
assign(array $params, array $list = [], string $assignmentFilter = self::BLACKLIST)

Update the object with an associative array.

from  Model
void
beforeDelete()

This runs before delete, needs to return a boolean

from  Model
void
beforeSave()

Implements beforeSave.

data()

Grab object and if we just need data for smaller result set.

from  Model
bool
delete()

Wrapper for database delete function. If not softDelete we set it.

from  Model
static array
getColumns()

Gets columns from table.

from  Model
array
getColumnsForSave()

Gets an associative array of field values for insert or updating.

from  Model
static DB
getDb()

Returns an instance of the DB class.

from  Model
array
getErrorMessages()

Displays error messages when form validation fails.

from  Model
static array
_fetchStyleParams(array $params)

Used to set default fetchStyle param.

from  Model
static array|bool
find(array $params = [])

Wrapper for the find function that is found in the DB class.

from  Model
static object|bool
findById(int $id)

Get result from database by primary key ID.

from  Model
static array|bool
findByTable(string $table, array $params = [])

Performs a database query against a specified table using the same query-building logic as the default find method.

from  Model
static array
findAllByUserId(int $user_id, array $params = [])

Retrieves list of all records within a table related to a user.

from  Model
static object|bool
findFirst(array $params = [])

Wrapper for the findFirst function that is found in the DB class.

from  Model
static int
findTotal(array $params = [])

Returns number of records in a table. A wrapper function for findTotal function in DB class.

from  Model
bool
insert(array $fields)

Wrapper for database insert function.

from  Model
bool
isNew()

Checks if an object is a new insertion or an existing record.

from  Model
void
onConstruct()

Runs when the object is constructed.

from  Model
void
populateObjData(array|object $result)

Populates object with data.

from  Model
DB
query(string $sql, array $bind = [])

Wrapper for database query function.

from  Model
void
runValidation(object $validator)

Runs a validator object and sets validates boolean and adds error message if validator fails.

from  Model
bool
save()

Wrapper for update and insert functions. A failed form validation will cause this function to return false.

from  Model
static array
_softDeleteParams(array $params)

Adds to the conditions to avoid getting soft deleted rows returned

from  Model
void
timeStamps()

Sets values for timestamp fields.

from  Model
bool
update(array $fields)

Wrapper for the update function found in the DB class.

from  Model
static int
updateWhere(array $fields, array $params)

Updates one or more rows in this model's underlying table using your framework's params-style conditions.

from  Model
bool
validationPassed()

Getter function for the $_validates boolean instance variable.

from  Model
void
validator()

Function that is called on save. If validation fails the save function will not proceed. This function is just a signature and must be implemented by models that run form validation because since it is called from within this class.

from  Model
static int
calcRetryDelay(Queue $job, array|null $payload)

Calculate delay when performing retry for a job.

static void
exceptionMessaging(FrameworkException $e, array $queueJob)

Handles tasks related to exceptions and retry of jobs.

static string
failedAt()

Logs message indicating job permanently failed and returns current timestamp.

static Queue|null
findFirstWithLock(string $queueName)

Find first with lock

static Queue|null
findJob(array $queueJob)

Returns record for job based on id found in associative array.

static bool
hasExceededMaxAttempts(DB $db, Queue $job)

Test if job as exceeded limit for maximum allowed attempts.

static bool
isQueueableClass(mixed $jobClass)

Checks if class exists and that it implements the QueueableJobInterface.

static int
maxAttempts(array $payload)

Returns maximum allowable attempts.

static Queue
reservedAt(DB $db, Queue $job)

Updates reserved_at field.

static Queue|null
reserveNext(string $queueName)

Attempts to atomically reserve the next available job from the queue.

static int
resolveBackoffDelay(mixed $backoff, Queue $job)

Resolves backoff delay.

static void
setAvailableAt(int $delay, Queue $job)

Sets when job is available.

static void
updateAttempts(Queue $job)

Updates information about attempts.

Details

in Model at line 68
__construct()

Default constructor.

in Model at line 82
void addErrorMessage(string $field, string $message)

Generates error messages that occur during form validation.

Parameters

string $field

The form field associated with failed form validation

string $message

A message that describes to the user the cause for failed form validation.

Return Value

void

in Model at line 95
void afterDelete()

Called before delete.

Return Value

void

in Model at line 102
void afterSave()

Called before save.

Return Value

void

in Model at line 114
Model assign(array $params, array $list = [], string $assignmentFilter = self::BLACKLIST)

Update the object with an associative array.

Parameters

array $params

Take values from post array and assign values.

array $list

A list of values to blacklist or whitelist.

string $assignmentFilter

When set to ModelName::BLACKLIST the values in the $list array is blacklisted. When set to ModelName::WHITELIST they are whitelisted.

Return Value

Model

Report for whether or not the operation was successful.

in Model at line 137
void beforeDelete()

This runs before delete, needs to return a boolean

Return Value

void

Boolean value depending on results of operation.

at line 84
void beforeSave()

Implements beforeSave.

Return Value

void

in Model at line 151
stdClass data()

Grab object and if we just need data for smaller result set.

Return Value

stdClass

The data associated with an object.

in Model at line 178
bool delete()

Wrapper for database delete function. If not softDelete we set it.

If row is set to softDelete we call the database delete function.

Return Value

bool

$deleted True if delete operation is successful. Otherwise, we return false.

in Model at line 196
static array getColumns()

Gets columns from table.

Return Value

array

An array of objects where each one represents a column from a database table.

in Model at line 206
array getColumnsForSave()

Gets an associative array of field values for insert or updating.

Return Value

array

Associative array of fields from database and values from model object.

in Model at line 234
static DB getDb()

Returns an instance of the DB class.

Return Value

DB

$_db The instance of the DB class.

in Model at line 247
array getErrorMessages()

Displays error messages when form validation fails.

Return Value

array

An array that contains a list of items that failed form validation.

in Model at line 257
static protected array _fetchStyleParams(array $params)

Used to set default fetchStyle param.

Parameters

array $params

Query params.

Return Value

array

$params Updated params.

in Model at line 271
static array|bool find(array $params = [])

Wrapper for the find function that is found in the DB class.

Parameters

array $params

The values for the query. They are the fields of the table in our database. The default value is an empty array.

Return Value

array|bool

An array of objects returned from an SQL query.

in Model at line 285
static object|bool findById(int $id)

Get result from database by primary key ID.

Parameters

int $id

The ID of the row we want to retrieve from the database.

Return Value

object|bool

The row from a database.

in Model at line 301
static array|bool findByTable(string $table, array $params = [])

Performs a database query against a specified table using the same query-building logic as the default find method.

This method is useful when querying a different table than the one defined by the model's static::$_table property (e.g., joining or selecting from related tables).

Parameters

string $table

The name of the table to query (can include alias, e.g. 'cart_items AS items').

array $params

The query parameters such as columns, joins, conditions, bind, order, limit, etc.

Return Value

array|bool

An array of result objects if found, or false/empty array if no results.

in Model at line 317
static array findAllByUserId(int $user_id, array $params = [])

Retrieves list of all records within a table related to a user.

Parameters

int $user_id

The user ID.

array $params

Used to build conditions for database query. The default value is an empty array.

Return Value

array

The list of records that is returned from the database.

in Model at line 335
static object|bool findFirst(array $params = [])

Wrapper for the findFirst function that is found in the DB class.

Parameters

array $params

The values for the query. They are the fields of the table in our database. The default value is an empty array.

Return Value

object|bool

An array of object returned from an SQL query.

in Model at line 350
static int findTotal(array $params = [])

Returns number of records in a table. A wrapper function for findTotal function in DB class.

Parameters

array $params

The values for the query. They are the fields of the table in our database. The default value is an empty array.

Return Value

int

The number of records in a table.

in Model at line 365
bool insert(array $fields)

Wrapper for database insert function.

Parameters

array $fields

The field names and the respective values we will use to populate a database record. The default value is an empty array.

Return Value

bool

Report for whether or not the operation was successful.

in Model at line 377
bool isNew()

Checks if an object is a new insertion or an existing record.

Return Value

bool

Returns true if the record exists. Otherwise, we return false.

in Model at line 386
void onConstruct()

Runs when the object is constructed.

Return Value

void

in Model at line 394
protected void populateObjData(array|object $result)

Populates object with data.

Parameters

array|object $result

Results from a database query.

Return Value

void

in Model at line 409
DB query(string $sql, array $bind = [])

Wrapper for database query function.

Parameters

string $sql

The database query we will submit to the database.

array $bind

The values we want to bind in our database query. The default value is an empty array.

Return Value

DB

The results of the database query.

in Model at line 420
void runValidation(object $validator)

Runs a validator object and sets validates boolean and adds error message if validator fails.

Parameters

object $validator

The validator object.

Return Value

void

in Model at line 435
bool save()

Wrapper for update and insert functions. A failed form validation will cause this function to return false.

Return Value

bool

True if the update operation is successful. Otherwise, we return false.

in Model at line 470
static protected array _softDeleteParams(array $params)

Adds to the conditions to avoid getting soft deleted rows returned

Parameters

array $params

Defined parameters to search by.

Return Value

array

$params parameters with appended conditions for soft delete.

in Model at line 496
void timeStamps()

Sets values for timestamp fields.

Return Value

void

in Model at line 512
bool update(array $fields)

Wrapper for the update function found in the DB class.

Parameters

array $fields

The value of the fields we want to set for the database record. The default value is an empty array.

Return Value

bool

True if the update operation is successful. Otherwise, we return false.

in Model at line 542
static int updateWhere(array $fields, array $params)

Updates one or more rows in this model's underlying table using your framework's params-style conditions.

This method delegates to the DB::updateWhere() method and allows you to pass both the fields to update and a parameterized WHERE clause (using conditions and bind arrays just like find/findFirst).

Example:

Queue::updateWhere(
    ['reserved_at' => date('Y-m-d H:i:s')],
    ['conditions' => 'id = ?', 'bind' => [$jobId]]
);

Parameters

array $fields

Associative array of columns to update with their new values. Example: ['status' => 'processed', 'attempts' => 3]

array $params

Query parameters for the WHERE clause. Supports:

  • conditions (string|array): SQL conditions with placeholders.
  • bind (array): Values to bind to placeholders.

Return Value

int

The number of rows affected by the update.

in Model at line 552
bool validationPassed()

Getter function for the $_validates boolean instance variable.

Return Value

bool

$_validates is true if validation is successful and false if there is a failure.

in Model at line 563
void validator()

Function that is called on save. If validation fails the save function will not proceed. This function is just a signature and must be implemented by models that run form validation because since it is called from within this class.

Return Value

void

at line 66
static private int calcRetryDelay(Queue $job, array|null $payload)

Calculate delay when performing retry for a job.

Parameters

Queue $job

The job to perform.

array|null $payload

Data related job.

Return Value

int

The calculated delay.

at line 95
static void exceptionMessaging(FrameworkException $e, array $queueJob)

Handles tasks related to exceptions and retry of jobs.

Parameters

FrameworkException $e

The exception.

array $queueJob

The array of jobs

Return Value

void

at line 119
static private string failedAt()

Logs message indicating job permanently failed and returns current timestamp.

Return Value

string

Current timestamp.

at line 130
static private Queue|null findFirstWithLock(string $queueName)

Find first with lock

Parameters

string $queueName

The name of the queue.

Return Value

Queue|null

The queue.

at line 147
static private Queue|null findJob(array $queueJob)

Returns record for job based on id found in associative array.

Parameters

array $queueJob

An array containing information about a job.

Return Value

Queue|null

The record if it exists or null.

at line 160
static private bool hasExceededMaxAttempts(DB $db, Queue $job)

Test if job as exceeded limit for maximum allowed attempts.

Parameters

DB $db

Instance of DB class.

Queue $job

Queue model.

Return Value

bool

True if exceeded maximum allowed attempts, otherwise false.

at line 182
static private bool isQueueableClass(mixed $jobClass)

Checks if class exists and that it implements the QueueableJobInterface.

Parameters

mixed $jobClass

The name of the job class.

Return Value

bool

True if class exists and implements correct interface. Otherwise, we return false.

at line 192
static private int maxAttempts(array $payload)

Returns maximum allowable attempts.

Parameters

array $payload

Information stored in payload array.

Return Value

int

The maximum number of allowable attempts.

at line 203
static private Queue reservedAt(DB $db, Queue $job)

Updates reserved_at field.

Parameters

DB $db

Instance of DB class.

Queue $job

Queue model.

Return Value

Queue

This instance of Queue model passed as parameter.

at line 239
static Queue|null reserveNext(string $queueName)

Attempts to atomically reserve the next available job from the queue.

This method wraps the operation in a database transaction and uses a SELECT ... FOR UPDATE query (when supported) to safely fetch the next unreserved job in the specified queue. Once a job is found, it immediately updates the reserved_at timestamp to mark it as reserved and prevent other workers from picking it up.

Usage example:

$job = Queue::reserveNext('default');
if ($job) {
    // Process the job...
}

Parameters

string $queueName

The name of the queue to pull from (e.g. "default").

Return Value

Queue|null

Returns an instance of the job model with the job data if a job was reserved, or null if no available job was found at this time.

Exceptions

FrameworkException

at line 268
static private int resolveBackoffDelay(mixed $backoff, Queue $job)

Resolves backoff delay.

Parameters

mixed $backoff

Time to backoff.

Queue $job

The queue to backoff.

Return Value

int

The delay.

at line 284
static private void setAvailableAt(int $delay, Queue $job)

Sets when job is available.

Parameters

int $delay

The delay.

Queue $job

The job in the queue.

Return Value

void

at line 295
static private void updateAttempts(Queue $job)

Updates information about attempts.

Parameters

Queue $job

The job whose attempts we want to update.

Return Value

void