@unchainedshop/plugins 3.1.14 → 4.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/delivery/pick-mup.js +0 -2
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/files/gridfs/adapter.d.ts.map +1 -1
- package/lib/files/gridfs/adapter.js +3 -2
- package/lib/files/gridfs/adapter.js.map +1 -1
- package/lib/files/gridfs/handler-express.d.ts.map +1 -1
- package/lib/files/gridfs/handler-express.js +6 -2
- package/lib/files/gridfs/handler-express.js.map +1 -1
- package/lib/files/gridfs/handler-fastify.d.ts.map +1 -1
- package/lib/files/gridfs/handler-fastify.js +5 -2
- package/lib/files/gridfs/handler-fastify.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +2 -2
- package/lib/files/gridfs/module.d.ts.map +1 -1
- package/lib/filters/local-search.d.ts.map +1 -1
- package/lib/filters/local-search.js +9 -2
- package/lib/filters/local-search.js.map +1 -1
- package/lib/filters/strict-equal.js +18 -0
- package/lib/filters/strict-equal.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +6 -13
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/fix-periods.d.ts.map +1 -1
- package/lib/payment/apple-iap/fix-periods.js +3 -5
- package/lib/payment/apple-iap/fix-periods.js.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +4 -4
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +4 -4
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module.d.ts +2 -2
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/braintree.js +3 -4
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -2
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.js.map +1 -1
- package/lib/payment/cryptopay/handle-webhook.js +1 -1
- package/lib/payment/cryptopay/handle-webhook.js.map +1 -1
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +4 -57
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.js +4 -56
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/module.d.ts +26 -26
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +26 -24
- package/lib/payment/cryptopay/module.js.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +33 -79
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/api/types.d.ts +41 -41
- package/lib/payment/datatrans-v2/api/types.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +2 -2
- package/lib/payment/datatrans-v2/getPaths.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/index.js +16 -14
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +3 -3
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/paypal-checkout.js +6 -8
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +2 -2
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/index.js +4 -4
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/payrexx.js +2 -2
- package/lib/payment/payrexx/payrexx.js.map +1 -1
- package/lib/payment/postfinance-checkout/api-client.d.ts +16 -0
- package/lib/payment/postfinance-checkout/api-client.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/api-client.js +75 -0
- package/lib/payment/postfinance-checkout/api-client.js.map +1 -0
- package/lib/payment/postfinance-checkout/api-types.d.ts +98 -0
- package/lib/payment/postfinance-checkout/api-types.d.ts.map +1 -0
- package/lib/payment/postfinance-checkout/api-types.js +51 -0
- package/lib/payment/postfinance-checkout/api-types.js.map +1 -0
- package/lib/payment/postfinance-checkout/api.d.ts +5 -5
- package/lib/payment/postfinance-checkout/api.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/api.js +38 -62
- package/lib/payment/postfinance-checkout/api.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-express.js +5 -5
- package/lib/payment/postfinance-checkout/handler-express.js.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/handler-fastify.js +6 -6
- package/lib/payment/postfinance-checkout/handler-fastify.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.d.ts +2 -1
- package/lib/payment/postfinance-checkout/index.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +27 -30
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/types.d.ts +4 -4
- package/lib/payment/postfinance-checkout/types.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.d.ts +3 -3
- package/lib/payment/postfinance-checkout/utils.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.js +5 -6
- package/lib/payment/postfinance-checkout/utils.js.map +1 -1
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.js +4 -6
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/api/models/Transaction.d.ts +2 -2
- package/lib/payment/saferpay/api/models/Transaction.d.ts.map +1 -1
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/saferpay/module.d.ts.map +1 -1
- package/lib/payment/stripe/index.js +5 -5
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/stripe.js +3 -3
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/presets/all.d.ts +15 -13
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/presets/all.js +3 -1
- package/lib/presets/all.js.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +2 -2
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-delivery.js +1 -1
- package/lib/pricing/order-delivery.js.map +1 -1
- package/lib/pricing/order-discount.js +3 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +1 -1
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/order-items.js +1 -1
- package/lib/pricing/order-items.js.map +1 -1
- package/lib/pricing/order-payment.js +1 -1
- package/lib/pricing/order-payment.js.map +1 -1
- package/lib/pricing/order-round.d.ts +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +8 -8
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +0 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +6 -18
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +2 -2
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-round.d.ts +1 -1
- package/lib/pricing/product-round.d.ts.map +1 -1
- package/lib/pricing/product-round.js +2 -2
- package/lib/pricing/product-round.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -1
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +2 -2
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/warehousing/eth-minter.js +2 -2
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/budgetsms.d.ts +10 -0
- package/lib/worker/budgetsms.d.ts.map +1 -0
- package/lib/worker/budgetsms.js +217 -0
- package/lib/worker/budgetsms.js.map +1 -0
- package/lib/worker/bulk-import.js +1 -1
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/bulkgate.d.ts +2 -0
- package/lib/worker/bulkgate.d.ts.map +1 -0
- package/lib/worker/bulkgate.js +104 -0
- package/lib/worker/bulkgate.js.map +1 -0
- package/lib/worker/enrollment-order-generator.js +1 -1
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.d.ts +4 -4
- package/lib/worker/error-notifications.d.ts.map +1 -1
- package/lib/worker/heartbeat.js +2 -8
- package/lib/worker/heartbeat.js.map +1 -1
- package/lib/worker/message.d.ts +1 -1
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/sms.js +16 -16
- package/lib/worker/sms.js.map +1 -1
- package/lib/worker/twilio.d.ts +2 -0
- package/lib/worker/twilio.d.ts.map +1 -0
- package/lib/worker/twilio.js +56 -0
- package/lib/worker/twilio.js.map +1 -0
- package/lib/worker/update-coinbase-rates.js +1 -1
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/package.json +32 -53
- package/src/delivery/pick-mup.ts +0 -2
- package/src/files/gridfs/adapter.ts +7 -2
- package/src/files/gridfs/handler-express.ts +9 -2
- package/src/files/gridfs/handler-fastify.ts +8 -2
- package/src/files/gridfs/module.ts +2 -2
- package/src/filters/local-search.ts +11 -2
- package/src/filters/strict-equal.ts +21 -0
- package/src/payment/apple-iap/adapter.ts +7 -14
- package/src/payment/apple-iap/fix-periods.ts +4 -7
- package/src/payment/apple-iap/handler-express.ts +4 -4
- package/src/payment/apple-iap/handler-fastify.ts +4 -4
- package/src/payment/apple-iap/module.ts +2 -2
- package/src/payment/braintree.ts +3 -4
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -2
- package/src/payment/cryptopay/denote-amount.test.ts +28 -0
- package/src/payment/cryptopay/denote-amount.ts +29 -0
- package/src/payment/cryptopay/derive-btc-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-btc-address.ts +48 -0
- package/src/payment/cryptopay/derive-eth-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-eth-address.ts +38 -0
- package/src/payment/cryptopay/handle-webhook.ts +103 -0
- package/src/payment/cryptopay/handler-express.ts +4 -70
- package/src/payment/cryptopay/handler-fastify.ts +6 -71
- package/src/payment/cryptopay/module.ts +44 -40
- package/src/payment/cryptopay/plugin.ts +50 -87
- package/src/payment/cryptopay/readme.md +23 -1
- package/src/payment/datatrans-v2/api/types.ts +41 -41
- package/src/payment/datatrans-v2/getPaths.ts +2 -2
- package/src/payment/datatrans-v2/index.ts +17 -15
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +4 -4
- package/src/payment/paypal-checkout.ts +6 -11
- package/src/payment/payrexx/api/index.ts +2 -2
- package/src/payment/payrexx/api/makeFetcher.ts +1 -1
- package/src/payment/payrexx/index.ts +4 -4
- package/src/payment/payrexx/payrexx.ts +2 -2
- package/src/payment/postfinance-checkout/api-client.ts +106 -0
- package/src/payment/postfinance-checkout/api-types.ts +111 -0
- package/src/payment/postfinance-checkout/api.ts +58 -85
- package/src/payment/postfinance-checkout/handler-express.ts +5 -7
- package/src/payment/postfinance-checkout/handler-fastify.ts +6 -8
- package/src/payment/postfinance-checkout/index.ts +43 -35
- package/src/payment/postfinance-checkout/types.ts +6 -6
- package/src/payment/postfinance-checkout/utils.ts +7 -12
- package/src/payment/saferpay/adapter.ts +4 -6
- package/src/payment/saferpay/api/models/Transaction.ts +2 -2
- package/src/payment/saferpay/module.ts +2 -2
- package/src/payment/stripe/index.ts +5 -5
- package/src/payment/stripe/stripe.ts +3 -3
- package/src/presets/all.ts +3 -1
- package/src/pricing/delivery-swiss-tax.ts +6 -2
- package/src/pricing/order-delivery.ts +1 -1
- package/src/pricing/order-discount.ts +3 -3
- package/src/pricing/order-items-discount.ts +1 -1
- package/src/pricing/order-items.ts +1 -1
- package/src/pricing/order-payment.ts +1 -1
- package/src/pricing/order-round.ts +9 -9
- package/src/pricing/product-catalog-price.ts +6 -25
- package/src/pricing/product-price-rateconversion.ts +2 -2
- package/src/pricing/product-round.ts +3 -3
- package/src/pricing/product-swiss-tax.test.ts +6 -6
- package/src/pricing/product-swiss-tax.ts +2 -2
- package/src/warehousing/eth-minter.ts +2 -2
- package/src/worker/budgetsms.ts +268 -0
- package/src/worker/bulk-import.ts +1 -1
- package/src/worker/bulkgate.ts +138 -0
- package/src/worker/enrollment-order-generator.ts +3 -3
- package/src/worker/error-notifications.ts +4 -4
- package/src/worker/heartbeat.ts +4 -11
- package/src/worker/message.ts +1 -1
- package/src/worker/push-notification.ts +2 -2
- package/src/worker/twilio.ts +71 -0
- package/src/worker/update-coinbase-rates.ts +3 -6
- package/src/worker/update-ecb-rates.ts +3 -3
- package/lib/accounts/google-oauth.d.ts +0 -4
- package/lib/accounts/google-oauth.d.ts.map +0 -1
- package/lib/accounts/google-oauth.js +0 -145
- package/lib/accounts/google-oauth.js.map +0 -1
- package/lib/accounts/linkedin-oauth.d.ts +0 -4
- package/lib/accounts/linkedin-oauth.d.ts.map +0 -1
- package/lib/accounts/linkedin-oauth.js +0 -82
- package/lib/accounts/linkedin-oauth.js.map +0 -1
- package/lib/files/gridfs/gridfs-adapter.d.ts +0 -3
- package/lib/files/gridfs/gridfs-adapter.d.ts.map +0 -1
- package/lib/files/gridfs/gridfs-adapter.js +0 -97
- package/lib/files/gridfs/gridfs-adapter.js.map +0 -1
- package/lib/files/gridfs/gridfs-webhook.d.ts +0 -11
- package/lib/files/gridfs/gridfs-webhook.d.ts.map +0 -1
- package/lib/files/gridfs/gridfs-webhook.js +0 -84
- package/lib/files/gridfs/gridfs-webhook.js.map +0 -1
- package/lib/files/minio/minio-adapter.d.ts +0 -6
- package/lib/files/minio/minio-adapter.d.ts.map +0 -1
- package/lib/files/minio/minio-adapter.js +0 -181
- package/lib/files/minio/minio-adapter.js.map +0 -1
- package/lib/files/minio/minio-webhook.d.ts +0 -2
- package/lib/files/minio/minio-webhook.d.ts.map +0 -1
- package/lib/files/minio/minio-webhook.js +0 -33
- package/lib/files/minio/minio-webhook.js.map +0 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts +0 -9
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.d.ts.map +0 -1
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js +0 -17
- package/lib/payment/apple-iap/module/configureAppleTransactionsModule.js.map +0 -1
- package/lib/payment/cryptopay/middleware.d.ts +0 -2
- package/lib/payment/cryptopay/middleware.d.ts.map +0 -1
- package/lib/payment/cryptopay/middleware.js +0 -75
- package/lib/payment/cryptopay/middleware.js.map +0 -1
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts +0 -25
- package/lib/payment/cryptopay/module/configureCryptopayModule.d.ts.map +0 -1
- package/lib/payment/cryptopay/module/configureCryptopayModule.js +0 -75
- package/lib/payment/cryptopay/module/configureCryptopayModule.js.map +0 -1
- package/lib/payment/datatrans-v2/middleware.d.ts +0 -2
- package/lib/payment/datatrans-v2/middleware.d.ts.map +0 -1
- package/lib/payment/datatrans-v2/middleware.js +0 -68
- package/lib/payment/datatrans-v2/middleware.js.map +0 -1
- package/lib/payment/payrexx/middleware.d.ts +0 -2
- package/lib/payment/payrexx/middleware.d.ts.map +0 -1
- package/lib/payment/payrexx/middleware.js +0 -86
- package/lib/payment/payrexx/middleware.js.map +0 -1
- package/lib/payment/postfinance-checkout/middleware.d.ts +0 -2
- package/lib/payment/postfinance-checkout/middleware.d.ts.map +0 -1
- package/lib/payment/postfinance-checkout/middleware.js +0 -38
- package/lib/payment/postfinance-checkout/middleware.js.map +0 -1
- package/lib/payment/saferpay/middleware.d.ts +0 -2
- package/lib/payment/saferpay/middleware.d.ts.map +0 -1
- package/lib/payment/saferpay/middleware.js +0 -57
- package/lib/payment/saferpay/middleware.js.map +0 -1
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts +0 -10
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.d.ts.map +0 -1
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js +0 -24
- package/lib/payment/saferpay/module/configureSaferpayTransactionsModule.js.map +0 -1
- package/lib/payment/stripe/middleware.d.ts +0 -6
- package/lib/payment/stripe/middleware.d.ts.map +0 -1
- package/lib/payment/stripe/middleware.js +0 -114
- package/lib/payment/stripe/middleware.js.map +0 -1
- package/lib/plugins-index.d.ts +0 -48
- package/lib/plugins-index.d.ts.map +0 -1
- package/lib/plugins-index.js +0 -107
- package/lib/plugins-index.js.map +0 -1
- package/lib/worker/BaseWorker.d.ts +0 -30
- package/lib/worker/BaseWorker.d.ts.map +0 -1
- package/lib/worker/BaseWorker.js +0 -79
- package/lib/worker/BaseWorker.js.map +0 -1
- package/lib/worker/EventListenerWorker.d.ts +0 -6
- package/lib/worker/EventListenerWorker.d.ts.map +0 -1
- package/lib/worker/EventListenerWorker.js +0 -46
- package/lib/worker/EventListenerWorker.js.map +0 -1
- package/lib/worker/FailedRescheduler.d.ts +0 -15
- package/lib/worker/FailedRescheduler.d.ts.map +0 -1
- package/lib/worker/FailedRescheduler.js +0 -45
- package/lib/worker/FailedRescheduler.js.map +0 -1
- package/lib/worker/IntervalWorker.d.ts +0 -10
- package/lib/worker/IntervalWorker.d.ts.map +0 -1
- package/lib/worker/IntervalWorker.js +0 -37
- package/lib/worker/IntervalWorker.js.map +0 -1
- package/src/worker/BaseWorker.ts +0 -116
- package/src/worker/EventListenerWorker.ts +0 -61
- package/src/worker/FailedRescheduler.ts +0 -80
- package/src/worker/IntervalWorker.ts +0 -54
- package/src/worker/sms.ts +0 -87
package/lib/worker/BaseWorker.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import later from '@breejs/later';
|
|
2
|
-
import { WorkerDirector } from '@unchainedshop/core';
|
|
3
|
-
export const BaseWorker = {
|
|
4
|
-
key: 'shop.unchained.worker.base',
|
|
5
|
-
label: 'Base worker. Do not use this directly.',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
type: 'BASE',
|
|
8
|
-
external: false,
|
|
9
|
-
getFloorDate: (date = new Date()) => {
|
|
10
|
-
const floored = new Date(Math.floor(date.getTime() / 1000) * 1000);
|
|
11
|
-
return floored;
|
|
12
|
-
},
|
|
13
|
-
actions: ({ workerId }, unchainedAPI) => {
|
|
14
|
-
const workerActions = {
|
|
15
|
-
start() {
|
|
16
|
-
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
17
|
-
},
|
|
18
|
-
stop() {
|
|
19
|
-
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
20
|
-
},
|
|
21
|
-
reset: async (referenceDate = new Date()) => {
|
|
22
|
-
await unchainedAPI.modules.worker.markOldWorkAsFailed({
|
|
23
|
-
types: WorkerDirector.getActivePluginTypes({ external: false }),
|
|
24
|
-
worker: workerId,
|
|
25
|
-
referenceDate,
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
autorescheduleTypes: async ({ referenceDate }) => {
|
|
29
|
-
return Promise.all(WorkerDirector.getAutoSchedules().map(async ([scheduleId, workConfig]) => {
|
|
30
|
-
if (!workConfig.schedule) {
|
|
31
|
-
await unchainedAPI.modules.worker.ensureNoWork({
|
|
32
|
-
type: workConfig.type,
|
|
33
|
-
priority: workConfig.priority || 0,
|
|
34
|
-
scheduleId,
|
|
35
|
-
});
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const fixedSchedule = { ...workConfig.schedule };
|
|
39
|
-
fixedSchedule.schedules[0].s = [0]; // ignore seconds, always run on second 0
|
|
40
|
-
const nextDate = later.schedule(fixedSchedule).next(1, referenceDate);
|
|
41
|
-
nextDate.setMilliseconds(0);
|
|
42
|
-
const workData = {
|
|
43
|
-
type: workConfig.type,
|
|
44
|
-
scheduleId,
|
|
45
|
-
scheduled: nextDate,
|
|
46
|
-
timeout: workConfig.timeout,
|
|
47
|
-
priority: workConfig.priority || 0,
|
|
48
|
-
retries: workConfig.retries || 0,
|
|
49
|
-
};
|
|
50
|
-
if (workConfig.input) {
|
|
51
|
-
workData.input = await workConfig.input(workData);
|
|
52
|
-
// A work input fn can skip auto scheduling a new record
|
|
53
|
-
// when it explicitly returns a falsish input instead of a dictionary
|
|
54
|
-
if (!workData.input)
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
return unchainedAPI.modules.worker.ensureOneWork(workData);
|
|
58
|
-
}));
|
|
59
|
-
},
|
|
60
|
-
process: async ({ maxWorkItemCount, referenceDate }) => {
|
|
61
|
-
await workerActions.autorescheduleTypes({
|
|
62
|
-
referenceDate,
|
|
63
|
-
});
|
|
64
|
-
const processRecursively = async (recursionCounter = 0) => {
|
|
65
|
-
if (maxWorkItemCount && maxWorkItemCount < recursionCounter)
|
|
66
|
-
return null;
|
|
67
|
-
const doneWork = await WorkerDirector.processNextWork(unchainedAPI, workerId);
|
|
68
|
-
if (doneWork)
|
|
69
|
-
return processRecursively(recursionCounter + 1);
|
|
70
|
-
return null;
|
|
71
|
-
};
|
|
72
|
-
await processRecursively();
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
workerActions.reset();
|
|
76
|
-
return workerActions;
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
//# sourceMappingURL=BaseWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseWorker.js","sourceRoot":"","sources":["../../src/worker/BaseWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,eAAe,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA4BrD,MAAM,CAAC,MAAM,UAAU,GAA0B;IAC/C,GAAG,EAAE,4BAA4B;IACjC,KAAK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BACd,CAAC,CAAC;gBAEH,MAAM,kBAAkB,GAAG,KAAK,EAAE,gBAAgB,GAAG,CAAC,EAAE,EAAE;oBACxD,IAAI,gBAAgB,IAAI,gBAAgB,GAAG,gBAAgB;wBAAE,OAAO,IAAI,CAAC;oBACzE,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,eAAe,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;oBAC9E,IAAI,QAAQ;wBAAE,OAAO,kBAAkB,CAAC,gBAAgB,GAAG,CAAC,CAAC,CAAC;oBAC9D,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;gBAEF,MAAM,kBAAkB,EAAE,CAAC;YAC7B,CAAC;SACF,CAAC;QAEF,aAAa,CAAC,KAAK,EAAE,CAAC;QAEtB,OAAO,aAAa,CAAC;IACvB,CAAC;CACF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventListenerWorker.d.ts","sourceRoot":"","sources":["../../src/worker/EventListenerWorker.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,OAAO,EAAE,MAAM,iBAAiB,CAAC;AActD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,mBAAmB,EAAE,OAAO,CAAC,yBAAyB,CAyClE,CAAC"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { subscribe } from '@unchainedshop/events';
|
|
2
|
-
import { BaseWorker } from './BaseWorker.js';
|
|
3
|
-
import { WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
4
|
-
function debounce(func, wait) {
|
|
5
|
-
let timeout;
|
|
6
|
-
return (...args) => {
|
|
7
|
-
clearTimeout(timeout);
|
|
8
|
-
timeout = setTimeout(() => {
|
|
9
|
-
timeout = null;
|
|
10
|
-
func(...args);
|
|
11
|
-
}, wait);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export const EventListenerWorker = {
|
|
15
|
-
...BaseWorker,
|
|
16
|
-
key: 'shop.unchained.worker.event-listener',
|
|
17
|
-
label: 'Allocates work on events. This worker does not make sense on multiple containers.',
|
|
18
|
-
version: '1.0.0',
|
|
19
|
-
type: 'EVENT_LISTENER',
|
|
20
|
-
actions: ({ workerId }, unchainedAPI) => {
|
|
21
|
-
const baseWorkerActions = BaseWorker.actions({ workerId, worker: EventListenerWorker }, unchainedAPI);
|
|
22
|
-
// Debounce in the event of many work queue events conflicting with each other
|
|
23
|
-
const processWorkQueue = debounce(async () => {
|
|
24
|
-
await baseWorkerActions.process({
|
|
25
|
-
maxWorkItemCount: 1, // only one work item at a time, else we could end up in a loop
|
|
26
|
-
referenceDate: EventListenerWorker.getFloorDate(),
|
|
27
|
-
});
|
|
28
|
-
}, 300);
|
|
29
|
-
return {
|
|
30
|
-
...baseWorkerActions,
|
|
31
|
-
start() {
|
|
32
|
-
subscribe(WorkerEventTypes.ADDED, processWorkQueue);
|
|
33
|
-
subscribe(WorkerEventTypes.FINISHED, processWorkQueue);
|
|
34
|
-
setTimeout(async () => {
|
|
35
|
-
await baseWorkerActions.autorescheduleTypes({
|
|
36
|
-
referenceDate: EventListenerWorker.getFloorDate(),
|
|
37
|
-
});
|
|
38
|
-
}, 300);
|
|
39
|
-
},
|
|
40
|
-
stop() {
|
|
41
|
-
/* */
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=EventListenerWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventListenerWorker.js","sourceRoot":"","sources":["../../src/worker/EventListenerWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAW,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,SAAS,QAAQ,CAAkC,IAAO,EAAE,IAAI;IAC9D,I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,CAAC;YACV,CAAC;YAED,IAAI;gBACF,KAAK;YACP,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { WorkData } from '@unchainedshop/core-worker';
|
|
2
|
-
export interface FailedReschedulerParams {
|
|
3
|
-
retryInput?: (workData: WorkData, priorInput: Record<string, any>) => Promise<Record<string, any> | null>;
|
|
4
|
-
}
|
|
5
|
-
export type IScheduler<P> = {
|
|
6
|
-
key: string;
|
|
7
|
-
label: string;
|
|
8
|
-
version: string;
|
|
9
|
-
actions: (params: P, unchainedAPI: any) => {
|
|
10
|
-
start: () => void;
|
|
11
|
-
stop: () => void;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare const FailedRescheduler: IScheduler<FailedReschedulerParams>;
|
|
15
|
-
//# sourceMappingURL=FailedRescheduler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FailedRescheduler.d.ts","sourceRoot":"","sources":["../../src/worker/FailedRescheduler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,QAAQ,EAAoB,MAAM,4BAA4B,CAAC;AAE9E,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,CACX,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;CAC1C;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAEhB,OAAO,EAAE,CACP,MAAM,EAAE,CAAC,EACT,YAAY,KAAA,KACT;QACH,KAAK,EAAE,MAAM,IAAI,CAAC;QAClB,IAAI,EAAE,MAAM,IAAI,CAAC;KAClB,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,UAAU,CAAC,uBAAuB,CAsDjE,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { defaultLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { subscribe } from '@unchainedshop/events';
|
|
3
|
-
import { WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
4
|
-
export const FailedRescheduler = {
|
|
5
|
-
key: 'shop.unchained.scheduler.failed',
|
|
6
|
-
label: 'Reschedule failed works',
|
|
7
|
-
version: '1.0.0',
|
|
8
|
-
actions: ({ retryInput }, unchainedAPI) => {
|
|
9
|
-
const handleFinishedWork = async ({ payload: work }) => {
|
|
10
|
-
if (!work.success && work.retries > 0) {
|
|
11
|
-
const now = new Date();
|
|
12
|
-
const workDelayMs = work.scheduled.getTime() - work.created.getTime();
|
|
13
|
-
// In short: Double the delay of the old work or delay for 5 seconds
|
|
14
|
-
const scheduled = workDelayMs > 1000
|
|
15
|
-
? new Date(now.getTime() + workDelayMs * 2)
|
|
16
|
-
: new Date(now.setSeconds(now.getSeconds() + 5));
|
|
17
|
-
defaultLogger.error(`${FailedRescheduler.key} -> Reschedule failed work ${work._id} ${work.type} for ${scheduled.toISOString()} (in ${Math.round(workDelayMs / 1000)}). Remaining retries: ${work.retries}`);
|
|
18
|
-
const workData = {
|
|
19
|
-
type: work.type,
|
|
20
|
-
priority: work.priority,
|
|
21
|
-
originalWorkId: work.originalWorkId || work._id,
|
|
22
|
-
retries: work.retries - 1,
|
|
23
|
-
timeout: work.timeout,
|
|
24
|
-
scheduled,
|
|
25
|
-
};
|
|
26
|
-
if (retryInput) {
|
|
27
|
-
workData.input = await retryInput(workData, work.input);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
workData.input = work.input;
|
|
31
|
-
}
|
|
32
|
-
unchainedAPI.modules.worker.addWork(workData);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
start() {
|
|
37
|
-
subscribe(WorkerEventTypes.FINISHED, handleFinishedWork);
|
|
38
|
-
},
|
|
39
|
-
stop() {
|
|
40
|
-
/* */
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
//# sourceMappingURL=FailedRescheduler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FailedRescheduler.js","sourceRoot":"","sources":["../../src/worker/FailedRescheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAkB,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAuB9E,MAAM,CAAC,MAAM,iBAAiB,GAAwC;IACpE,GAAG,EAAE,iCAAiC;IACtC,KAAK,EAAE,yBAAyB;IAChC,OAAO,EAAE,OAAO;IAEhB,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,YAAY,EAAE,EAAE;QACxC,MAAM,kBAAkB,GAAG,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAqB,EAAE,EAAE;YACxE,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;gBACtC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;gBACvB,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;gBAEtE,oEAAoE;gBACpE,MAAM,SAAS,GACb,WAAW,GAAG,IAAI;oBAChB,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,WAAW,GAAG,CAAC,CAAC;oBAC3C,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;gBAErD,aAAa,CAAC,KAAK,CACjB,GAAG,iBAAiB,CAAC,GAAG,8BAA8B,IAAI,CAAC,GAAG,IAC5D,IAAI,CAAC,IACP,QAAQ,SAAS,CAAC,WAAW,EAAE,QAAQ,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,yBACnE,IAAI,CAAC,OACP,EAAE,CACH,CAAC;gBAEF,MAAM,QAAQ,GAAa;oBACzB,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,GAAG;oBAC/C,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,CAAC;oBACzB,OAAO,EAAE,IAAI,CAAC,OAAO;oBACrB,SAAS;iBACV,CAAC;gBAEF,IAAI,UAAU,EAAE,CAAC;oBACf,QAAQ,CAAC,KAAK,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC1D,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;gBAC9B,CAAC;gBAED,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAChD,CAAC;QACH,CAAC,CAAC;QAEF,OAAO;YACL,KAAK;gBACH,SAAS,CAAO,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;YACjE,CAAC;YAED,IAAI;gBACF,KAAK;YACP,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ScheduleData } from '@breejs/later';
|
|
2
|
-
import { IWorker } from './BaseWorker.js';
|
|
3
|
-
export interface IntervalWorkerParams {
|
|
4
|
-
workerId?: string;
|
|
5
|
-
batchCount?: number;
|
|
6
|
-
schedule?: ScheduleData;
|
|
7
|
-
}
|
|
8
|
-
export declare const scheduleToInterval: (schedule: ScheduleData) => number;
|
|
9
|
-
export declare const IntervalWorker: IWorker<IntervalWorkerParams>;
|
|
10
|
-
//# sourceMappingURL=IntervalWorker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntervalWorker.d.ts","sourceRoot":"","sources":["../../src/worker/IntervalWorker.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAc,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAItD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB;AAMD,eAAO,MAAM,kBAAkB,GAAI,UAAU,YAAY,WAKxD,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,oBAAoB,CA+BxD,CAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import later from '@breejs/later';
|
|
2
|
-
import { BaseWorker } from './BaseWorker.js';
|
|
3
|
-
const { NODE_ENV } = process.env;
|
|
4
|
-
const defaultSchedule = later.parse.text(NODE_ENV !== 'production' ? 'every 2 seconds' : 'every 30 seconds');
|
|
5
|
-
export const scheduleToInterval = (schedule) => {
|
|
6
|
-
const referenceDate = new Date(1000);
|
|
7
|
-
const [one, two] = later.schedule(schedule).next(2, referenceDate);
|
|
8
|
-
const diff = new Date(two).getTime() - new Date(one).getTime();
|
|
9
|
-
return Math.min(1000 * 60 * 60, diff); // at least once every hour!
|
|
10
|
-
};
|
|
11
|
-
export const IntervalWorker = {
|
|
12
|
-
...BaseWorker,
|
|
13
|
-
key: 'shop.unchained.worker.cron',
|
|
14
|
-
label: 'Allocates work on fixed intervals with native node setInterval',
|
|
15
|
-
version: '1.0.0',
|
|
16
|
-
type: 'CRON',
|
|
17
|
-
actions: ({ workerId, batchCount = 0, schedule = defaultSchedule }, unchainedAPI) => {
|
|
18
|
-
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
|
|
19
|
-
const intervalDelay = scheduleToInterval(schedule);
|
|
20
|
-
let intervalHandle;
|
|
21
|
-
return {
|
|
22
|
-
...baseWorkerActions,
|
|
23
|
-
start() {
|
|
24
|
-
intervalHandle = setInterval(() => {
|
|
25
|
-
baseWorkerActions.process({
|
|
26
|
-
maxWorkItemCount: batchCount,
|
|
27
|
-
referenceDate: IntervalWorker.getFloorDate(),
|
|
28
|
-
});
|
|
29
|
-
}, intervalDelay);
|
|
30
|
-
},
|
|
31
|
-
stop() {
|
|
32
|
-
clearInterval(intervalHandle);
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
//# sourceMappingURL=IntervalWorker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IntervalWorker.js","sourceRoot":"","sources":["../../src/worker/IntervalWorker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAuB,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,UAAU,EAAW,MAAM,iBAAiB,CAAC;AAEtD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAQjC,MAAM,eAAe,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CACtC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,kBAAkB,CACnE,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAsB,EAAE,EAAE;IAC3D,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,aAAa,CAAW,CAAC;IAC7E,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;IAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,4BAA4B;AACrE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAkC;IAC3D,GAAG,UAAU;IAEb,GAAG,EAAE,4BAA4B;IACjC,KAAK,EAAE,gEAAgE;IACvE,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,MAAM;IAEZ,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,GAAG,CAAC,EAAE,QAAQ,GAAG,eAAe,EAAE,EAAE,YAAY,EAAE,EAAE;QAClF,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,YAAY,CAAC,CAAC;QAEjG,MAAM,aAAa,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,cAA8B,CAAC;QAEnC,OAAO;YACL,GAAG,iBAAiB;YAEpB,KAAK;gBACH,cAAc,GAAG,WAAW,CAAC,GAAG,EAAE;oBAChC,iBAAiB,CAAC,OAAO,CAAC;wBACxB,gBAAgB,EAAE,UAAU;wBAC5B,aAAa,EAAE,cAAc,CAAC,YAAY,EAAE;qBAC7C,CAAC,CAAC;gBACL,CAAC,EAAE,aAAa,CAAC,CAAC;YACpB,CAAC;YAED,IAAI;gBACF,aAAa,CAAC,cAAc,CAAC,CAAC;YAChC,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/src/worker/BaseWorker.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import later from '@breejs/later';
|
|
2
|
-
import { Work, WorkData } from '@unchainedshop/core-worker';
|
|
3
|
-
import { WorkerDirector } from '@unchainedshop/core';
|
|
4
|
-
|
|
5
|
-
export type IWorker<P extends { workerId?: string }> = {
|
|
6
|
-
key: string;
|
|
7
|
-
label: string;
|
|
8
|
-
version: string;
|
|
9
|
-
type: string;
|
|
10
|
-
external: boolean;
|
|
11
|
-
|
|
12
|
-
getFloorDate: (date?: Date) => Date;
|
|
13
|
-
|
|
14
|
-
actions: (
|
|
15
|
-
params: P,
|
|
16
|
-
unchainedAPI,
|
|
17
|
-
) => {
|
|
18
|
-
autorescheduleTypes: (options: { referenceDate: Date }) => Promise<Array<Work | null>>;
|
|
19
|
-
process: (options: { maxWorkItemCount?: number; referenceDate?: Date }) => Promise<void>;
|
|
20
|
-
reset: () => Promise<void>;
|
|
21
|
-
start: () => void;
|
|
22
|
-
stop: () => void;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
interface WorkerParams {
|
|
27
|
-
workerId?: string;
|
|
28
|
-
worker: IWorker<any>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const BaseWorker: IWorker<WorkerParams> = {
|
|
32
|
-
key: 'shop.unchained.worker.base',
|
|
33
|
-
label: 'Base worker. Do not use this directly.',
|
|
34
|
-
version: '1.0.0',
|
|
35
|
-
type: 'BASE',
|
|
36
|
-
external: false,
|
|
37
|
-
|
|
38
|
-
getFloorDate: (date = new Date()) => {
|
|
39
|
-
const floored = new Date(Math.floor(date.getTime() / 1000) * 1000);
|
|
40
|
-
return floored;
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
actions: ({ workerId }: WorkerParams, unchainedAPI) => {
|
|
44
|
-
const workerActions = {
|
|
45
|
-
start() {
|
|
46
|
-
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
stop() {
|
|
50
|
-
throw new Error(`Not implemented on ${this.constructor.key}`);
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
reset: async (referenceDate = new Date()) => {
|
|
54
|
-
await unchainedAPI.modules.worker.markOldWorkAsFailed({
|
|
55
|
-
types: WorkerDirector.getActivePluginTypes({ external: false }),
|
|
56
|
-
worker: workerId,
|
|
57
|
-
referenceDate,
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
autorescheduleTypes: async ({ referenceDate }) => {
|
|
62
|
-
return Promise.all(
|
|
63
|
-
WorkerDirector.getAutoSchedules().map(async ([scheduleId, workConfig]) => {
|
|
64
|
-
if (!workConfig.schedule) {
|
|
65
|
-
await unchainedAPI.modules.worker.ensureNoWork({
|
|
66
|
-
type: workConfig.type,
|
|
67
|
-
priority: workConfig.priority || 0,
|
|
68
|
-
scheduleId,
|
|
69
|
-
});
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const fixedSchedule = { ...workConfig.schedule };
|
|
74
|
-
fixedSchedule.schedules[0].s = [0]; // ignore seconds, always run on second 0
|
|
75
|
-
const nextDate = later.schedule(fixedSchedule).next(1, referenceDate) as Date;
|
|
76
|
-
nextDate.setMilliseconds(0);
|
|
77
|
-
const workData: WorkData = {
|
|
78
|
-
type: workConfig.type,
|
|
79
|
-
scheduleId,
|
|
80
|
-
scheduled: nextDate,
|
|
81
|
-
timeout: workConfig.timeout,
|
|
82
|
-
priority: workConfig.priority || 0,
|
|
83
|
-
retries: workConfig.retries || 0,
|
|
84
|
-
};
|
|
85
|
-
if (workConfig.input) {
|
|
86
|
-
workData.input = await workConfig.input(workData);
|
|
87
|
-
// A work input fn can skip auto scheduling a new record
|
|
88
|
-
// when it explicitly returns a falsish input instead of a dictionary
|
|
89
|
-
if (!workData.input) return null;
|
|
90
|
-
}
|
|
91
|
-
return unchainedAPI.modules.worker.ensureOneWork(workData);
|
|
92
|
-
}),
|
|
93
|
-
);
|
|
94
|
-
},
|
|
95
|
-
|
|
96
|
-
process: async ({ maxWorkItemCount, referenceDate }) => {
|
|
97
|
-
await workerActions.autorescheduleTypes({
|
|
98
|
-
referenceDate,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const processRecursively = async (recursionCounter = 0) => {
|
|
102
|
-
if (maxWorkItemCount && maxWorkItemCount < recursionCounter) return null;
|
|
103
|
-
const doneWork = await WorkerDirector.processNextWork(unchainedAPI, workerId);
|
|
104
|
-
if (doneWork) return processRecursively(recursionCounter + 1);
|
|
105
|
-
return null;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
await processRecursively();
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
workerActions.reset();
|
|
113
|
-
|
|
114
|
-
return workerActions;
|
|
115
|
-
},
|
|
116
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { subscribe } from '@unchainedshop/events';
|
|
2
|
-
import { BaseWorker, IWorker } from './BaseWorker.js';
|
|
3
|
-
import { WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
4
|
-
|
|
5
|
-
function debounce<T extends (...args: any) => any>(func: T, wait) {
|
|
6
|
-
let timeout;
|
|
7
|
-
return (...args) => {
|
|
8
|
-
clearTimeout(timeout);
|
|
9
|
-
timeout = setTimeout(() => {
|
|
10
|
-
timeout = null;
|
|
11
|
-
func(...args);
|
|
12
|
-
}, wait);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface EventListenerWorkerParams {
|
|
17
|
-
workerId?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const EventListenerWorker: IWorker<EventListenerWorkerParams> = {
|
|
21
|
-
...BaseWorker,
|
|
22
|
-
|
|
23
|
-
key: 'shop.unchained.worker.event-listener',
|
|
24
|
-
label: 'Allocates work on events. This worker does not make sense on multiple containers.',
|
|
25
|
-
version: '1.0.0',
|
|
26
|
-
type: 'EVENT_LISTENER',
|
|
27
|
-
|
|
28
|
-
actions: ({ workerId }, unchainedAPI) => {
|
|
29
|
-
const baseWorkerActions = BaseWorker.actions(
|
|
30
|
-
{ workerId, worker: EventListenerWorker },
|
|
31
|
-
unchainedAPI,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
// Debounce in the event of many work queue events conflicting with each other
|
|
35
|
-
const processWorkQueue = debounce<() => Promise<void>>(async () => {
|
|
36
|
-
await baseWorkerActions.process({
|
|
37
|
-
maxWorkItemCount: 1, // only one work item at a time, else we could end up in a loop
|
|
38
|
-
referenceDate: EventListenerWorker.getFloorDate(),
|
|
39
|
-
});
|
|
40
|
-
}, 300);
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
...baseWorkerActions,
|
|
44
|
-
|
|
45
|
-
start() {
|
|
46
|
-
subscribe(WorkerEventTypes.ADDED, processWorkQueue);
|
|
47
|
-
subscribe(WorkerEventTypes.FINISHED, processWorkQueue);
|
|
48
|
-
|
|
49
|
-
setTimeout(async () => {
|
|
50
|
-
await baseWorkerActions.autorescheduleTypes({
|
|
51
|
-
referenceDate: EventListenerWorker.getFloorDate(),
|
|
52
|
-
});
|
|
53
|
-
}, 300);
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
stop() {
|
|
57
|
-
/* */
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
},
|
|
61
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { defaultLogger } from '@unchainedshop/logger';
|
|
2
|
-
import { subscribe } from '@unchainedshop/events';
|
|
3
|
-
import { Work, WorkData, WorkerEventTypes } from '@unchainedshop/core-worker';
|
|
4
|
-
|
|
5
|
-
export interface FailedReschedulerParams {
|
|
6
|
-
retryInput?: (
|
|
7
|
-
workData: WorkData,
|
|
8
|
-
priorInput: Record<string, any>,
|
|
9
|
-
) => Promise<Record<string, any> | null>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type IScheduler<P> = {
|
|
13
|
-
key: string;
|
|
14
|
-
label: string;
|
|
15
|
-
version: string;
|
|
16
|
-
|
|
17
|
-
actions: (
|
|
18
|
-
params: P,
|
|
19
|
-
unchainedAPI,
|
|
20
|
-
) => {
|
|
21
|
-
start: () => void;
|
|
22
|
-
stop: () => void;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const FailedRescheduler: IScheduler<FailedReschedulerParams> = {
|
|
27
|
-
key: 'shop.unchained.scheduler.failed',
|
|
28
|
-
label: 'Reschedule failed works',
|
|
29
|
-
version: '1.0.0',
|
|
30
|
-
|
|
31
|
-
actions: ({ retryInput }, unchainedAPI) => {
|
|
32
|
-
const handleFinishedWork = async ({ payload: work }: { payload: Work }) => {
|
|
33
|
-
if (!work.success && work.retries > 0) {
|
|
34
|
-
const now = new Date();
|
|
35
|
-
const workDelayMs = work.scheduled.getTime() - work.created.getTime();
|
|
36
|
-
|
|
37
|
-
// In short: Double the delay of the old work or delay for 5 seconds
|
|
38
|
-
const scheduled =
|
|
39
|
-
workDelayMs > 1000
|
|
40
|
-
? new Date(now.getTime() + workDelayMs * 2)
|
|
41
|
-
: new Date(now.setSeconds(now.getSeconds() + 5));
|
|
42
|
-
|
|
43
|
-
defaultLogger.error(
|
|
44
|
-
`${FailedRescheduler.key} -> Reschedule failed work ${work._id} ${
|
|
45
|
-
work.type
|
|
46
|
-
} for ${scheduled.toISOString()} (in ${Math.round(workDelayMs / 1000)}). Remaining retries: ${
|
|
47
|
-
work.retries
|
|
48
|
-
}`,
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const workData: WorkData = {
|
|
52
|
-
type: work.type,
|
|
53
|
-
priority: work.priority,
|
|
54
|
-
originalWorkId: work.originalWorkId || work._id,
|
|
55
|
-
retries: work.retries - 1,
|
|
56
|
-
timeout: work.timeout,
|
|
57
|
-
scheduled,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
if (retryInput) {
|
|
61
|
-
workData.input = await retryInput(workData, work.input);
|
|
62
|
-
} else {
|
|
63
|
-
workData.input = work.input;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
unchainedAPI.modules.worker.addWork(workData);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
start() {
|
|
72
|
-
subscribe<Work>(WorkerEventTypes.FINISHED, handleFinishedWork);
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
stop() {
|
|
76
|
-
/* */
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import later, { ScheduleData } from '@breejs/later';
|
|
2
|
-
import { BaseWorker, IWorker } from './BaseWorker.js';
|
|
3
|
-
|
|
4
|
-
const { NODE_ENV } = process.env;
|
|
5
|
-
|
|
6
|
-
export interface IntervalWorkerParams {
|
|
7
|
-
workerId?: string;
|
|
8
|
-
batchCount?: number;
|
|
9
|
-
schedule?: ScheduleData;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const defaultSchedule = later.parse.text(
|
|
13
|
-
NODE_ENV !== 'production' ? 'every 2 seconds' : 'every 30 seconds',
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
export const scheduleToInterval = (schedule: ScheduleData) => {
|
|
17
|
-
const referenceDate = new Date(1000);
|
|
18
|
-
const [one, two] = later.schedule(schedule).next(2, referenceDate) as Date[];
|
|
19
|
-
const diff = new Date(two).getTime() - new Date(one).getTime();
|
|
20
|
-
return Math.min(1000 * 60 * 60, diff); // at least once every hour!
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const IntervalWorker: IWorker<IntervalWorkerParams> = {
|
|
24
|
-
...BaseWorker,
|
|
25
|
-
|
|
26
|
-
key: 'shop.unchained.worker.cron',
|
|
27
|
-
label: 'Allocates work on fixed intervals with native node setInterval',
|
|
28
|
-
version: '1.0.0',
|
|
29
|
-
type: 'CRON',
|
|
30
|
-
|
|
31
|
-
actions: ({ workerId, batchCount = 0, schedule = defaultSchedule }, unchainedAPI) => {
|
|
32
|
-
const baseWorkerActions = BaseWorker.actions({ workerId, worker: IntervalWorker }, unchainedAPI);
|
|
33
|
-
|
|
34
|
-
const intervalDelay = scheduleToInterval(schedule);
|
|
35
|
-
let intervalHandle: NodeJS.Timeout;
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
...baseWorkerActions,
|
|
39
|
-
|
|
40
|
-
start() {
|
|
41
|
-
intervalHandle = setInterval(() => {
|
|
42
|
-
baseWorkerActions.process({
|
|
43
|
-
maxWorkItemCount: batchCount,
|
|
44
|
-
referenceDate: IntervalWorker.getFloorDate(),
|
|
45
|
-
});
|
|
46
|
-
}, intervalDelay);
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
stop() {
|
|
50
|
-
clearInterval(intervalHandle);
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
},
|
|
54
|
-
};
|