UNPKG

@unchainedshop/plugins

Version:

Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec

37 lines 1.54 kB
import later from '@breejs/later'; import { BaseWorker } from './BaseWorker.js'; const { NODE_ENV } = process.env; const defaultSchedule = later.parse.text(NODE_ENV !== 'production' ? 'every 2 seconds' : 'every 30 seconds'); export const scheduleToInterval = (schedule) => { const referenceDate = new Date(1000); const [one, two] = later.schedule(schedule).next(2, referenceDate); const diff = new Date(two).getTime() - new Date(one).getTime(); return Math.min(1000 * 60 * 60, diff); // at least once every hour! }; export const IntervalWorker = { ...BaseWorker, key: 'shop.unchained.worker.cron', label: 'Allocates work on fixed intervals with native node setInterval', version: '1.0.0', type: 'CRON', actions: ({ workerId, batchCount = 0, schedule = defaultSchedule }, unchainedAPI) => { const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI); const intervalDelay = scheduleToInterval(schedule); let intervalHandle; return { ...baseWorkerActions, start() { intervalHandle = setInterval(() => { baseWorkerActions.process({ maxWorkItemCount: batchCount, referenceDate: IntervalWorker.getFloorDate(), }); }, intervalDelay); }, stop() { clearInterval(intervalHandle); }, }; }, }; //# sourceMappingURL=IntervalWorker.js.map