ElasticPresenter
extends BasePresenter
in package
Table of Contents
Properties
- $cronLockManager : CronLockManager
- $operationRunner : OperationRunner
- Boundary of one cron action (see {@see self::tryCall()}).
- $settingContext : SettingContext
- $settingManager : SettingManager
- $debugMode : bool
- $productionMode : bool
- $advertSource : AdvertDocumentSource
- $esIndexer : EsEntityIndexer
Methods
- __construct() : mixed
- actionReindex() : void
- Full reindex of adverts into a new index version with an atomic alias swap.
- actionSync() : void
- Incremental sync: indexes adverts inserted since the watermark and cleans up orphans.
- releaseLock() : void
- Releases the lock at most once; called by both `shutdown()` and the PHP shutdown function.
- sendResponse() : void
- setConfigParameters() : void
- shutdown() : void
- startup() : void
- isSameSiteRequest() : bool
- Tells whether the request comes from the own site (Nette SameSite cookie); protects GET actions with a side effect.
- sendError() : never
- sendSkipped() : never
- Reports that the job did only part of the work and the next call finishes the rest (e.g. a reindex done in chunks).
- sendSuccess() : never
- tryCall() : bool
- Runs the `action<Action>()` method as one operation (transitional).
Properties
$cronLockManager
public
CronLockManager
$cronLockManager
Attributes
- #[Inject]
$operationRunner
Boundary of one cron action (see {@see self::tryCall()}).
public
OperationRunner
$operationRunner
Attributes
- #[Inject]
$settingContext
public
SettingContext
$settingContext
Attributes
- #[Inject]
$settingManager
public
SettingManager
$settingManager
Attributes
- #[Inject]
$debugMode
protected
bool
$debugMode
= false
$productionMode
protected
bool
$productionMode
= false
$advertSource read-only
private
AdvertDocumentSource
$advertSource
$esIndexer read-only
private
EsEntityIndexer
$esIndexer
Methods
__construct()
public
__construct(EsEntityIndexer $esIndexer, AdvertDocumentSource $advertSource) : mixed
Parameters
- $esIndexer : EsEntityIndexer
- $advertSource : AdvertDocumentSource
actionReindex()
Full reindex of adverts into a new index version with an atomic alias swap.
public
actionReindex() : void
Zero downtime; a Redis lock prevents concurrent runs. This is the primary consistency guarantee: it also
catches mutations that bypass the save hooks (updateColumn() on paid/expiration/toped_until/deleted, recountPrices(), raw SQL), which the incremental sync cannot see.
Frequency: once a day, at night.
Runs in chunks (about 20 s per call, progress kept in Redis). Until finished it answers
status: skipped (reason: reindex_continues); the scheduler calls the job again on the next tick,
while a direct hosting cron must call it repeatedly until it returns status: ok.
The sync of the same source finishes an unfinished reindex as a safety net.
URL: /cron/bazaar/elastic/reindex?token=xxx
Attributes
- #[CronJob]
- $frequency: 'daily:02:00'
- $outbound: false
actionSync()
Incremental sync: indexes adverts inserted since the watermark and cleans up orphans.
public
actionSync() : void
The watermark lives in Redis (es:<indexPrefix>:watermark:bazaar_advert, 5 min overlap); orphans are
documents without a DB row. An advert has no update timestamp, so the sync catches only new adverts and
orphaned documents: edits are propagated by the completedSave hook, payments and expiration by targeted
triggers, everything else by the nightly full reindex.
Frequency: every 10 minutes.
URL: /cron/bazaar/elastic/sync?token=xxx
Attributes
- #[CronJob]
- $frequency: 'every:10'
- $outbound: false
releaseLock()
Releases the lock at most once; called by both `shutdown()` and the PHP shutdown function.
public
releaseLock() : void
sendResponse()
public
sendResponse(Response $response) : void
Parameters
- $response : Response
setConfigParameters()
public
setConfigParameters([bool $debugMode = false ][, bool $productionMode = false ]) : void
Parameters
- $debugMode : bool = false
- $productionMode : bool = false
shutdown()
public
shutdown(Response $response) : void
Parameters
- $response : Response
startup()
public
startup() : void
isSameSiteRequest()
Tells whether the request comes from the own site (Nette SameSite cookie); protects GET actions with a side effect.
protected
isSameSiteRequest() : bool
getHttpRequest() returns the IRequest interface, while isSameSite() exists only on
Nette\Http\Request.
Return values
boolsendError()
protected
sendError(string $message[, int $code = 500 ]) : never
Parameters
- $message : string
- $code : int = 500
Return values
neversendSkipped()
Reports that the job did only part of the work and the next call finishes the rest (e.g. a reindex done in chunks).
protected
sendSkipped(string $reason[, array<string, mixed> $data = [] ]) : never
The scheduler does not record skipped as a run, so the job stays due and is called
again on the next tick.
Parameters
- $reason : string
- $data : array<string, mixed> = []
Return values
neversendSuccess()
protected
sendSuccess([array<string|int, mixed> $data = [] ]) : never
Parameters
- $data : array<string|int, mixed> = []
Return values
nevertryCall()
Runs the `action<Action>()` method as one operation (transitional).
protected
tryCall(string $method, array<string, mixed> $params) : bool
Cron has no internalAction*(): its actions call the Api managers directly, so without this in
scoped mode nothing would ever empty the unit of work of a cron run. The boundary is the action
only; startup() (settings, token, lock) stays outside like the startup of an Api request. A cron
action ends with AbortException from send*(), which is a regular end: the outcome comes from the
response (ok succeeded, skipped unknown — possibly a part of a batch was done, error failed).
Render and signal methods are not wrapped (cron presenters have none).
Parameters
- $method : string
- $params : array<string, mixed>