NodeQueue
- Full name:
\Codefy\Framework\Queue\NodeQueue
- This class implements:
\Codefy\Framework\Queue\ReliableQueue
,\Codefy\Framework\Queue\QueueGarbageCollection
Properties
queue
db
Methods
__construct
Parameters:
Parameter | Type | Description |
---|---|---|
$queue | \Codefy\Framework\Queue\ShouldQueue | |
$node | ?string |
isDue
Parameters:
Parameter | Type | Description |
---|---|---|
$schedule | string|callable |
createItem
Adds a queue item and store it directly to the queue.
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.
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.
Return Value:
An integer estimate of the number of items in the queue.
claimItem
Claims an item in the queue for processing.
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.
Parameters:
Parameter | Type | Description |
---|---|---|
$item | mixed | The item returned by claimItem(). |
releaseItem
Releases an item that the worker could not process.
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.
deleteQueue
Deletes a queue and every item in the queue.
garbageCollection
Cleans queues of garbage.
Throws:
catchException
Act on an exception when queue might be stale.
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
Throws:
Inherited methods
cron
The Cron expression representing the task's frequency.
Parameters:
Parameter | Type | Description |
---|---|---|
$expression | string |
Throws:
filtersPass
Determine if the filters pass.
between
Schedule task to run between start and end time.
Parameters:
Parameter | Type | Description |
---|---|---|
$startTime | string | |
$endTime | string |
unlessBetween
Schedule task that doesn't fall between start and end time.
Parameters:
Parameter | Type | Description |
---|---|---|
$startTime | string | |
$endTime | string |
inTimeInterval
Schedule task to run between start and end time.
Parameters:
Parameter | Type | Description |
---|---|---|
$startTime | string | |
$endTime | string |
hourly
Schedule the task to run hourly.
Parameters:
Parameter | Type | Description |
---|---|---|
$minute | int|string |
Throws:
daily
Schedule the task to run daily.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
on
Schedule the task to run on a certain date.
Parameters:
Parameter | Type | Description |
---|---|---|
$date | string |
Throws:
at
Schedule the command at a given time.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
dailyAt
Schedule the task to run daily at a given time (10:00, 19:30, etc).
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
twiceDaily
Schedule the task to run twice daily.
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.
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.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
weekends
Schedule the task to run only on weekdays.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
mondays
Schedule the task to run only on Mondays.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
tuesdays
Schedule the task to run only on Tuesdays.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
wednesdays
Schedule the task to run only on Wednesdays.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
thursdays
Schedule the task to run only on Thursdays.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
fridays
Schedule the task to run only on Fridays.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
saturdays
Schedule the task to run only on Saturdays.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
sundays
Schedule the task to run only on Sundays.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | ?string |
Throws:
weekly
Schedule the task to run weekly.
Throws:
weeklyOn
Schedule the task to run weekly on a given day and time.
Parameters:
Parameter | Type | Description |
---|---|---|
$day | int|string | |
$time | string |
Throws:
monthly
Schedule the task to run monthly.
Throws:
monthlyOn
Schedule the task to run monthly on a given day and time.
Parameters:
Parameter | Type | Description |
---|---|---|
$dayOfMonth | int|string | |
$time | string |
Throws:
lastDayOfTheMonth
Schedule the task to run monthly on a given day and time.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | string |
Throws:
quarterly
Schedule the task to run quarterly.
Parameters:
Parameter | Type | Description |
---|---|---|
$day | int|string|array | |
$time | ?string |
Throws:
yearly
Schedule the task to run yearly.
Throws:
yearlyOn
Schedule the task to run yearly.
Parameters:
Parameter | Type | Description |
---|---|---|
$month | int | |
$day | int | |
$time | ?string |
Throws:
days
Set the days of the week the command should run on.
Parameters:
Parameter | Type | Description |
---|---|---|
$days | mixed |
Throws:
hour
Set hour for the cron job.
Parameters:
Parameter | Type | Description |
---|---|---|
$value | mixed |
Throws:
minute
Set minute for the cron job.
Parameters:
Parameter | Type | Description |
---|---|---|
$value | mixed |
Throws:
dayOfMonth
Set day of the month for the cron job.
Parameters:
Parameter | Type | Description |
---|---|---|
$value | mixed |
Throws:
month
Set month for the cron job.
Parameters:
Parameter | Type | Description |
---|---|---|
$value | mixed |
Throws:
dayOfWeek
Set dah of the week for the cron job.
Parameters:
Parameter | Type | Description |
---|---|---|
$value | mixed |
Throws:
timezone
Set the timezone the date should be evaluated on.
Parameters:
Parameter | Type | Description |
---|---|---|
$timezone | \DateTimeZone|string |
every
Another way to the frequency of the cron job.
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.
Parameters:
Parameter | Type | Description |
---|---|---|
$minute | string|int |
Throws:
everyHour
Schedule task to run every hour or every $hour hour and $minute minutes.
Parameters:
Parameter | Type | Description |
---|---|---|
$hour | string|int | |
$minute | int |
Throws:
expressionPasses
Determine if the Cron expression passes.
Parameters:
Parameter | Type | Description |
---|---|---|
$timezone | string|\DateTimeZone|null |
Throws:
spliceIntoPosition
Splice the given value into the given position of the expression.
Parameters:
Parameter | Type | Description |
---|---|---|
$position | int | |
$value | string |
Throws:
setDayOfWeek
Internal function used by the everyMonday, etc functions.
Parameters:
Parameter | Type | Description |
---|---|---|
$day | int|string | |
$time | ?string |
Throws:
parseTime
Parses a time string (like 4:08 pm) into minutes and hours.
Parameters:
Parameter | Type | Description |
---|---|---|
$time | string |
Automatically generated on 2025-10-13