Add priority tagging to carrier submissions
Node · Node · intermediate · modification
Adds express/standard priority tagging to carrier submissions so high-value orders get the faster lane. Tagging is applied in one place (a new buildSubmission helper) and gated behind the existing `priorityDispatch` config key — it's already plumbed through every environment and has sat dormant since the old path was retired, so ops can enable the feature without a config-schema change. With the flag off, submissions are byte-for-byte identical to today.
This dispatcher's runTick fires every 250ms in the fulfillment worker against the live carrier API; each carrier.submit() is a real shipment request, and duplicates are charged and have to be clawed back manually.
Requirements
- Add priority tagging: with the new feature enabled, every carrier submission gains a `priority` field — `'express'` when `order.valueCents >= 20000` (the EXPRESS_THRESHOLD_CENTS constant), `'standard'` otherwise. With it disabled, submissions stay byte-for-byte identical to today (no `priority` field).
- Gate the feature behind a config flag that is a no-op everywhere else: enabling it must change nothing in the dispatcher except adding the `priority` field to submissions.
- Do not delete or modify the retired legacy block in this PR — its removal is tracked separately (FUL-482). Its `priorityDispatch` flag is retired and must remain off in every environment.
- Input contract: orders are `{ id, sku, qty, valueCents }` with `valueCents` a non-negative integer; `state.acked` and `state.submitted` are Sets of order ids; `flags` is a plain object from the deploy config (absent keys mean off).
Files touched
- src/fulfillment/dispatch.js
--- src/fulfillment/dispatch.js
'use strict';
+
+const EXPRESS_THRESHOLD_CENTS = 20000;
// Feature flags come from the deploy config; absent keys read as off.
}
-function submitPending(order, carrier, state) {
+function buildSubmission(order, flags) {
+ const submission = { orderId: order.id, sku: order.sku, qty: order.qty };
+ if (flagOn(flags, 'priorityDispatch')) {
+ submission.priority =
+ order.valueCents >= EXPRESS_THRESHOLD_CENTS ? 'express' : 'standard';
+ }
+ return submission;
+}
+
+function submitPending(order, carrier, state, flags) {
if (state.acked.has(order.id) || state.submitted.has(order.id)) {
return;
}
- carrier.submit({ orderId: order.id, sku: order.sku, qty: order.qty });
+ carrier.submit(buildSubmission(order, flags));
state.submitted.add(order.id);
}
continue;
}
- submitPending(order, carrier, state);
+ submitPending(order, carrier, state, flags);