|
|
@@ -1,7 +1,80 @@
|
|
|
import logger from "../../utils/logger";
|
|
|
+import history from "../interface/history";
|
|
|
+import SwapPath from "../interface/swapPath";
|
|
|
|
|
|
-async function main() {
|
|
|
+class Level2Maintenance {
|
|
|
+ maxMemoryOfByte: number = 0
|
|
|
+ maxMemoryChanged: boolean = true
|
|
|
+ lpSumObj: any = {}
|
|
|
+
|
|
|
+ buildLpObj (lpList: any) {
|
|
|
+ for (const lp of lpList) {
|
|
|
+ lp.dataObj = JSON.parse(lp.data)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ showMemory (mainInfo: string) {
|
|
|
+ const memoryUsage = process.memoryUsage()
|
|
|
+ if (this.maxMemoryOfByte < memoryUsage.rss) {
|
|
|
+ this.maxMemoryOfByte = memoryUsage.rss
|
|
|
+ this.maxMemoryChanged = true
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.maxMemoryChanged) {
|
|
|
+ logger.debug(`${mainInfo} ${this.format(memoryUsage.rss)}/${this.format(this.maxMemoryOfByte)}`)
|
|
|
+
|
|
|
+ this.maxMemoryChanged = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ format (bytes: any) {
|
|
|
+ return (bytes / 1024 / 1024).toFixed(2) + ' MB';
|
|
|
+ }
|
|
|
+
|
|
|
+ async run() {
|
|
|
+ logger.debug('LP maintenance start.')
|
|
|
+ while (true) {
|
|
|
+ if (this.maxMemoryChanged) {
|
|
|
+ this.showMemory('a loop...')
|
|
|
+ }
|
|
|
+ this.maxMemoryChanged = false
|
|
|
+
|
|
|
+ this.lpSumObj = {}
|
|
|
|
|
|
+ const topLpPullRst = await history.findByBlock('topLp')
|
|
|
+ if (!topLpPullRst.state) continue
|
|
|
+ const topLpList = topLpPullRst.data
|
|
|
+ // const normalLpPullRst = await history.findByBlock('normalLp')
|
|
|
+ // if (!normalLpPullRst.state) continue
|
|
|
+ // const normalLpList = normalLpPullRst.data
|
|
|
+
|
|
|
+ const allTypeLpList: any = topLpList
|
|
|
+ this.buildLpObj(allTypeLpList)
|
|
|
+ logger.debug(`${allTypeLpList.length}`)
|
|
|
+
|
|
|
+ // 构造sum
|
|
|
+ logger.debug(`generate sum group by sum...`)
|
|
|
+ for (const lpDbObj of allTypeLpList) {
|
|
|
+ if (this.lpSumObj[lpDbObj.dataObj.sum2]) {
|
|
|
+ this.lpSumObj[lpDbObj.dataObj.sum2].push(lpDbObj.dataObj)
|
|
|
+ } else {
|
|
|
+ this.lpSumObj[lpDbObj.dataObj.sum2] = [lpDbObj.dataObj]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新所有sum
|
|
|
+ logger.debug(`update sum...`)
|
|
|
+ for (const sum2 of Object.keys(this.lpSumObj)) {
|
|
|
+ const lpList = this.lpSumObj[sum2]
|
|
|
+
|
|
|
+ await SwapPath.appendOrUpdate(sum2, '2', lpList)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function main() {
|
|
|
+ await new Level2Maintenance().run()
|
|
|
}
|
|
|
|
|
|
main().catch((error) => {
|