BufferChecker
in package
Table of Contents
Constants
- INFLIGHT_OPTION : mixed = 'wsc_api_buffer_inflight'
- MAX_ATTEMPTS : mixed = 3
- RETRY_ARGS : mixed = ['retry']
- RETRY_DELAY : mixed = 3600
Properties
- $actionName : string
- $checkCount : int
- $checkInterval : int
- $instance : self|null
Methods
- executeChecker() : void
- Executes the checker logic for processing the buffer.
- getInstance() : self
- Get the singleton instance of the BufferChecker class.
- oldestPendingAge() : int|false|null
- Age of the oldest webhook not yet propagated: the live buffer plus the one a run holds.
- productCount() : int
- The PIM sends one webhook per product AND language, so records over-count products by the number of languages edited: 11 products activated in every language is ~100 records.
- removeScheduledCron() : void
- Removes the scheduled cron job if it is set.
- scheduleChecker() : void
- Schedules the cron job that runs periodically to execute the checker.
- uniqueRecords() : array<int, array<string|int, mixed>>
- Drops repeated webhooks: one record per product and language, or per product when $perLang is false.
- updateOtherCollectionsSingleProduct() : bool
- Updates multiple product collections for a single product based on language and country.
- __construct() : mixed
- clearInflight() : void
- getAnyBlogId() : int|null
- isTypesenseReady() : bool
- Asks the node itself: cron runs in bulk mode, where TsHealth's breaker always reports available.
- updateAttributesCollection() : bool
- Updates attributes collection based on the given records.
- updateExternalProductsCollection() : bool
- Updates external products collection (only when a full regeneration is required).
- updateOtherCollections() : bool
- Updates localized collections derived from products.
- updateProductsCollection() : bool
- Updates the global ProductsCollection based on buffered product records.
- updateSingleProduct() : bool
- Updates a single product in the collection.
Constants
INFLIGHT_OPTION
private
mixed
INFLIGHT_OPTION
= 'wsc_api_buffer_inflight'
MAX_ATTEMPTS
private
mixed
MAX_ATTEMPTS
= 3
RETRY_ARGS
private
mixed
RETRY_ARGS
= ['retry']
RETRY_DELAY
private
mixed
RETRY_DELAY
= 3600
Properties
$actionName
private
string
$actionName
= 'wsc_check_api_buffer'
$checkCount
private
int
$checkCount
= 100
$checkInterval
private
int
$checkInterval
= 120
$instance
private
static self|null
$instance
= null
Methods
executeChecker()
Executes the checker logic for processing the buffer.
public
executeChecker() : void
This function will be triggered when the cron job is run.
getInstance()
Get the singleton instance of the BufferChecker class.
public
static getInstance() : self
Return values
self —The instance of BufferChecker.
oldestPendingAge()
Age of the oldest webhook not yet propagated: the live buffer plus the one a run holds.
public
static oldestPendingAge() : int|false|null
Return values
int|false|null —Seconds; null when nothing is pending, false when a buffer is unreadable.
productCount()
The PIM sends one webhook per product AND language, so records over-count products by the number of languages edited: 11 products activated in every language is ~100 records.
public
static productCount(array<string|int, array{search_id?: string}> $records) : int
Parameters
- $records : array<string|int, array{search_id?: string}>
Return values
intremoveScheduledCron()
Removes the scheduled cron job if it is set.
public
removeScheduledCron() : void
scheduleChecker()
Schedules the cron job that runs periodically to execute the checker.
public
scheduleChecker([string $context = "" ]) : void
This function will schedule the cron event to run every minute. It also registers a custom cron interval.
Parameters
- $context : string = ""
uniqueRecords()
Drops repeated webhooks: one record per product and language, or per product when $perLang is false.
public
static uniqueRecords(array<string|int, array{search_id?: string, lang?: string}> $records[, bool $perLang = true ]) : array<int, array<string|int, mixed>>
Parameters
- $records : array<string|int, array{search_id?: string, lang?: string}>
- $perLang : bool = true
Return values
array<int, array<string|int, mixed>>updateOtherCollectionsSingleProduct()
Updates multiple product collections for a single product based on language and country.
public
updateOtherCollectionsSingleProduct(string $id, array<string|int, mixed> $blogIds, array<string|int, mixed> $classes) : bool
This function iterates through all available countries where the given language is used, and updates the product in multiple collection instances.
Parameters
- $id : string
-
The product ID to update.
- $blogIds : array<string|int, mixed>
- $classes : array<string|int, mixed>
-
An array of collection class names to update.
Return values
bool —Returns true if all updates were successful, otherwise false.
__construct()
private
__construct() : mixed
clearInflight()
private
clearInflight() : void
getAnyBlogId()
private
getAnyBlogId() : int|null
Return values
int|nullisTypesenseReady()
Asks the node itself: cron runs in bulk mode, where TsHealth's breaker always reports available.
private
isTypesenseReady() : bool
Return values
boolupdateAttributesCollection()
Updates attributes collection based on the given records.
private
updateAttributesCollection(array<string|int, mixed> $records) : bool
Parameters
- $records : array<string|int, mixed>
Return values
boolupdateExternalProductsCollection()
Updates external products collection (only when a full regeneration is required).
private
updateExternalProductsCollection(bool $forceFullRebuild) : bool
Parameters
- $forceFullRebuild : bool
Return values
boolupdateOtherCollections()
Updates localized collections derived from products.
private
updateOtherCollections(array<string|int, mixed> $records, array<string|int, mixed> $langs[, bool $updateAllLocales = false ][, bool $forceFullRebuild = false ]) : bool
If the number of records exceeds a predefined threshold (or forceFullRebuild is true), entire collections are regenerated for each site. Otherwise, individual product documents are updated selectively.
Parameters
- $records : array<string|int, mixed>
-
List of product records to be updated.
- $langs : array<string|int, mixed>
-
List of languages for which the collections should be updated.
- $updateAllLocales : bool = false
-
Whether to update all locales for each record.
- $forceFullRebuild : bool = false
-
Forces full regeneration of localized collections.
Return values
bool —Returns true if all updates were successful, otherwise false.
updateProductsCollection()
Updates the global ProductsCollection based on buffered product records.
private
updateProductsCollection(array<string|int, mixed> $records[, bool $forceFull = false ]) : bool
If the number of records is below a predefined threshold, individual product documents are updated. Otherwise, the entire products collection is regenerated once (not per locale).
Parameters
- $records : array<string|int, mixed>
-
List of product records to be updated.
- $forceFull : bool = false
Return values
bool —Returns true if all updates were successful, otherwise false.
updateSingleProduct()
Updates a single product in the collection.
private
updateSingleProduct(string $id, ProductsCollection $productsColl) : bool
If the product update fails, it logs an error and returns false.
Parameters
- $id : string
-
The ID of the product to be updated.
- $productsColl : ProductsCollection
Return values
bool —Returns true if the product was successfully updated, otherwise false.