Skip to main content

Invalidate Carts Worker

Recalculates all open carts that were updated within the last maxAgeDays, so prices, taxes, and discounts stay current. Carts are recalculated sequentially to avoid saturating the MongoDB connection pool.

Included in Base Preset

Registered automatically by registerBasePlugins() / registerAllPlugins().

Registration​

import { pluginRegistry } from '@unchainedshop/core';
import { InvalidateCartsPlugin } from '@unchainedshop/plugins/worker/invalidate-carts';

pluginRegistry.register(InvalidateCartsPlugin);

Auto-Scheduling​

Runs automatically on the 1st of every month at 00:00 (cron 0 0 1 * *, retries 0), configured on registration. The cron is evaluated in the server's local timezone, so the year-boundary run lands at local midnight on January 1 — the moment new-year tax rates take effect. Keep the server's TZ set to the relevant tax jurisdiction.

Usage​

Trigger a recalculation manually:

mutation InvalidateCarts {
addWork(
type: INVALIDATE_CARTS
input: { maxAgeDays: 7 }
) {
_id
status
}
}

Input Parameters​

ParameterTypeDefaultDescription
maxAgeDaysNumber30Only carts updated within this many days are recalculated

Result​

{
"scannedCartCount": 0,
"recalculatedCartCount": 0
}

Adapter Details​

PropertyValue
Keyshop.unchained.worker-plugin.invalidate-carts
TypeINVALIDATE_CARTS
Auto-ScheduleMonthly, 1st at 00:00 local time
Retries0
Sourceworker/invalidate-carts