ProductImportPresenter
extends BasePresenter
in package
Product import queue: takes the oldest job in state `queued` and runs it ({@see ProductImportManager::run()}).
One run handles one job; the next waiting job is taken by the next minute.
Locking: the base class holds the generic lock cron.eshop.productimport.run (TTL 300 s), too short for a
long run. This class therefore uses its own lock LOCK_NAME with TTL LOCK_TTL, renewed after
every batch (heartbeat from the manager). Admin "run now"
(ProductImportRunTrait) holds the same lock, so a manual
and a cron run never overlap.
IMPORTANT: acquire() is fail-open: when the cms_cron_locks table is unavailable the job runs without
a lock (documented CronLockManager behavior).
Stuck runs: a run goes through HTTP (FPM time limit, process crash), so finally may not execute and the job
stays running forever. Before picking the queue, and only when nobody holds the run lock (otherwise the run
is alive), ProductImportManager::failStaleRunning() marks running jobs older than
ProductImportManager::STALE_RUNNING_SECONDS (twice the lock TTL) as failed and writes a log row.
This class cannot influence the FPM/proxy time limit; run() only disables the PHP max_execution_time.
URL: /cron/eshop/product-import/run?token=xxx
Table of Contents
Constants
- LOCK_NAME : string = 'cron.eshop.product-import.run'
- LOCK_TTL : int = 900
- Run lock TTL: longer than the default 300 s; every batch renews it.
Properties
- $cronLockManager : CronLockManager
- $operationRunner : OperationRunner
- Boundary of one cron action (see {@see self::tryCall()}).
- $settingContext : SettingContext
- $settingManager : SettingManager
- $debugMode : bool
- $productionMode : bool
- $productImportManager : ProductImportManager
Methods
- __construct() : mixed
- actionRun() : void
- Runs the oldest queued job.
- 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).
- findOldestQueued() : ProductImport|null
Constants
LOCK_NAME
public
string
LOCK_NAME
= 'cron.eshop.product-import.run'
LOCK_TTL
Run lock TTL: longer than the default 300 s; every batch renews it.
public
int
LOCK_TTL
= 900
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
$productImportManager read-only
private
ProductImportManager
$productImportManager
Methods
__construct()
public
__construct(ProductImportManager $productImportManager) : mixed
Parameters
- $productImportManager : ProductImportManager
actionRun()
Runs the oldest queued job.
public
actionRun() : void
Frequency: every minute.
Attributes
- #[CronJob]
- $frequency: 'every:1'
- $outbound: true
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>
Return values
boolfindOldestQueued()
private
findOldestQueued() : ProductImport|null