Skip to content

NodeQueue

Properties

queue

protected ?\Codefy\Framework\Queue\ShouldQueue $queue

db

private ?\Qubus\NoSql\Collection $db

Methods

__construct

public __construct(\Codefy\Framework\Queue\ShouldQueue $queue, ?string $node = null): mixed

Parameters:

Parameter Type Description
$queue \Codefy\Framework\Queue\ShouldQueue
$node ?string

isDue

public isDue(string|callable $schedule): bool

Parameters:

Parameter Type Description
$schedule string|callable

createItem

Adds a queue item and store it directly to the queue.

public createItem(): string

Return Value:

A unique ID if the item was successfully created and was (best effort) added to the queue, otherwise FALSE. We don't guarantee the item was committed to disk etc, but as far as we know, the item is now in the queue.


doCreateItem

Adds a queue item and store it directly to the queue.

protected doCreateItem(): string

Return Value:

A unique ID if the item was successfully created and was (best effort) added to the queue, otherwise false. We don't guarantee the item was committed to disk etc, but as far as we know, the item is now in the queue.

Throws:


numberOfItems

Retrieves the number of items in the queue.

public numberOfItems(): int

Return Value:

An integer estimate of the number of items in the queue.


claimItem

Claims an item in the queue for processing.

public claimItem(int $leaseTime = 3600): array|object|bool

Parameters:

Parameter Type Description
$leaseTime int How long the processing is expected to take in seconds,
defaults to an hour. After this lease expires, the item
will be reset and another consumer can claim the item.
For idempotent tasks (which can be run multiple times
without side effects), shorter lease times would result
in lower latency in case a consumer fails. For tasks
that should not be run more than once (non-idempotent),
a larger lease time will make it more rare for a given
task to run multiple times in cases of failure, at the
cost of higher latency.

Return Value:

On success, we return an item object|array. If the queue is unable to claim an item it returns false. This implies a best effort to retrieve an item and either the queue is empty or there is some other non-recoverable problem.

If returned, the object|array will have at least the following properties: - data: the same as what was passed into createItem(). - _id: the unique ID returned from createItem(). - created: timestamp when the item was put into the queue.


deleteItem

Deletes a finished item from the queue.

public deleteItem(mixed $item): void

Parameters:

Parameter Type Description
$item mixed The item returned by claimItem().

releaseItem

Releases an item that the worker could not process.

public releaseItem(mixed $item): bool

Parameters:

Parameter Type Description
$item mixed The item returned by claimItem().

Return Value:

TRUE if the item has been released, FALSE otherwise.


createQueue

Creates a queue.

public createQueue(): mixed

deleteQueue

Deletes a queue and every item in the queue.

public deleteQueue(): void

garbageCollection

Cleans queues of garbage.

public garbageCollection(): void

Throws:


catchException

Act on an exception when queue might be stale.

protected catchException(\Exception $e): void

If the node does not yet exist, that's fine, but if the node exists and yet the query failed, then the queue is stale and the exception needs to propagate.

Parameters:

Parameter Type Description
$e \Exception The exception.

Throws:


dispatch

public dispatch(): bool

Throws:


Inherited methods

cron

The Cron expression representing the task's frequency.

public cron(string $expression = '* * * * *'): self

Parameters:

Parameter Type Description
$expression string

Throws:


filtersPass

Determine if the filters pass.

public filtersPass(): bool

between

Schedule task to run between start and end time.

public between(string $startTime, string $endTime): self

Parameters:

Parameter Type Description
$startTime string
$endTime string

unlessBetween

Schedule task that doesn't fall between start and end time.

public unlessBetween(string $startTime, string $endTime): self

Parameters:

Parameter Type Description
$startTime string
$endTime string

inTimeInterval

Schedule task to run between start and end time.

private inTimeInterval(string $startTime, string $endTime): \Closure

Parameters:

Parameter Type Description
$startTime string
$endTime string

hourly

Schedule the task to run hourly.

public hourly(int|string $minute = 1): self

Parameters:

Parameter Type Description
$minute int|string

Throws:


daily

Schedule the task to run daily.

public daily(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


on

Schedule the task to run on a certain date.

public on(string $date): self

Parameters:

Parameter Type Description
$date string

Throws:


at

Schedule the command at a given time.

public at(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


dailyAt

Schedule the task to run daily at a given time (10:00, 19:30, etc).

public dailyAt(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


twiceDaily

Schedule the task to run twice daily.

public twiceDaily(int $first = 1, int $second = 13): self

Parameters:

Parameter Type Description
$first int First hour.
$second int Second hour.

Throws:


twiceDailyAt

Schedule the task to run twice daily at a given minute.

public twiceDailyAt(int $first = 1, int $second = 13, int $minute): self

Parameters:

Parameter Type Description
$first int First hour.
$second int Second hour.
$minute int Minute.

Throws:


weekdays

Schedule the task to run only on weekdays.

public weekdays(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


weekends

Schedule the task to run only on weekdays.

public weekends(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


mondays

Schedule the task to run only on Mondays.

public mondays(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


tuesdays

Schedule the task to run only on Tuesdays.

public tuesdays(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


wednesdays

Schedule the task to run only on Wednesdays.

public wednesdays(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


thursdays

Schedule the task to run only on Thursdays.

public thursdays(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


fridays

Schedule the task to run only on Fridays.

public fridays(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


saturdays

Schedule the task to run only on Saturdays.

public saturdays(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


sundays

Schedule the task to run only on Sundays.

public sundays(?string $time = null): self

Parameters:

Parameter Type Description
$time ?string

Throws:


weekly

Schedule the task to run weekly.

public weekly(): self

Throws:


weeklyOn

Schedule the task to run weekly on a given day and time.

public weeklyOn(int|string $day, string $time = '0:0'): self

Parameters:

Parameter Type Description
$day int|string
$time string

Throws:


monthly

Schedule the task to run monthly.

public monthly(): self

Throws:


monthlyOn

Schedule the task to run monthly on a given day and time.

public monthlyOn(int|string $dayOfMonth, string $time = '0:0'): self

Parameters:

Parameter Type Description
$dayOfMonth int|string
$time string

Throws:


lastDayOfTheMonth

Schedule the task to run monthly on a given day and time.

public lastDayOfTheMonth(string $time = '0:0'): self

Parameters:

Parameter Type Description
$time string

Throws:


quarterly

Schedule the task to run quarterly.

public quarterly(int|string|array $day = 1, ?string $time = null): self

Parameters:

Parameter Type Description
$day int|string|array
$time ?string

Throws:


yearly

Schedule the task to run yearly.

public yearly(): self

Throws:


yearlyOn

Schedule the task to run yearly.

public yearlyOn(int $month, int $day, ?string $time = null): self

Parameters:

Parameter Type Description
$month int
$day int
$time ?string

Throws:


days

Set the days of the week the command should run on.

public days(mixed $days): self

Parameters:

Parameter Type Description
$days mixed

Throws:


hour

Set hour for the cron job.

public hour(mixed $value): self

Parameters:

Parameter Type Description
$value mixed

Throws:


minute

Set minute for the cron job.

public minute(mixed $value): self

Parameters:

Parameter Type Description
$value mixed

Throws:


dayOfMonth

Set day of the month for the cron job.

public dayOfMonth(mixed $value): self

Parameters:

Parameter Type Description
$value mixed

Throws:


month

Set month for the cron job.

public month(mixed $value): self

Parameters:

Parameter Type Description
$value mixed

Throws:


dayOfWeek

Set dah of the week for the cron job.

public dayOfWeek(mixed $value): self

Parameters:

Parameter Type Description
$value mixed

Throws:


timezone

Set the timezone the date should be evaluated on.

public timezone(\DateTimeZone|string $timezone): $this

Parameters:

Parameter Type Description
$timezone \DateTimeZone|string

every

Another way to the frequency of the cron job.

public every(string|null $unit = null, float|int|null $value = null): self

Parameters:

Parameter Type Description
$unit string|null (minute, hour, day, month or weekday)
$value float|int|null

Throws:


everyMinute

Schedule task to run every minute of every $minute minutes.

public everyMinute(string|int $minute = 1): self

Parameters:

Parameter Type Description
$minute string|int

Throws:


everyHour

Schedule task to run every hour or every $hour hour and $minute minutes.

public everyHour(string|int $hour = 1, int $minute): self

Parameters:

Parameter Type Description
$hour string|int
$minute int

Throws:


expressionPasses

Determine if the Cron expression passes.

protected expressionPasses(string|\DateTimeZone|null $timezone = null): bool

Parameters:

Parameter Type Description
$timezone string|\DateTimeZone|null

Throws:


spliceIntoPosition

Splice the given value into the given position of the expression.

protected spliceIntoPosition(int $position, string $value): self

Parameters:

Parameter Type Description
$position int
$value string

Throws:


setDayOfWeek

Internal function used by the everyMonday, etc functions.

protected setDayOfWeek(int|string $day, ?string $time = null): self

Parameters:

Parameter Type Description
$day int|string
$time ?string

Throws:


parseTime

Parses a time string (like 4:08 pm) into minutes and hours.

protected parseTime(string $time): array

Parameters:

Parameter Type Description
$time string


Automatically generated on 2025-10-13