-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
824 additions
and
568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { OrderStatus } from "aws-sdk/clients/outposts"; | ||
import { Gauge, Histogram, collectDefaultMetrics } from "prom-client"; | ||
import { prisma } from ".."; | ||
import { orderStatus } from "@prisma/client"; | ||
|
||
collectDefaultMetrics(); | ||
|
||
const processingOrders = new Gauge({ | ||
name: "processing_orders", | ||
help: "Gauge of processing orders", | ||
labelNames: ["status"], | ||
}); | ||
const ordersCache = new Map<number, OrderStatus>(); | ||
const initOrdersCache = async () => { | ||
const orders = await prisma.order.findMany({ | ||
where: { | ||
status: { | ||
notIn: [ | ||
orderStatus.DELIVERED, | ||
orderStatus.CANCELLED, | ||
orderStatus.REJECTED, | ||
], | ||
}, | ||
}, | ||
}); | ||
orders.forEach((order) => { | ||
ordersCache.set(order.id, order.status); | ||
}); | ||
updateCounts(); | ||
}; | ||
initOrdersCache(); | ||
|
||
const updateCounts = () => { | ||
for (const status of Object.values(orderStatus)) { | ||
if (status === orderStatus.DELIVERED) continue; | ||
if (status === orderStatus.CANCELLED) continue; | ||
if (status === orderStatus.REJECTED) continue; | ||
const count = [...ordersCache.entries()].filter( | ||
([, s]) => s === status | ||
).length; | ||
processingOrders.set({ status }, count); | ||
} | ||
}; | ||
export const updateProcessingOrders = ( | ||
status: OrderStatus, | ||
orderNumber: number | ||
) => { | ||
if ( | ||
status === orderStatus.DELIVERED || | ||
status === orderStatus.CANCELLED || | ||
status === orderStatus.REJECTED | ||
) { | ||
ordersCache.delete(orderNumber); | ||
} else { | ||
ordersCache.set(orderNumber, status); | ||
} | ||
updateCounts(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters