-
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.
Merge pull request #43 from donghquinn/dev
Dev
- Loading branch information
Showing
37 changed files
with
543 additions
and
385 deletions.
There are no files selected for viewing
Binary file renamed
BIN
+237 KB
...mmon-npm-10.3.0-56be202040-bedb3437e6.zip → ...mmon-npm-10.3.1-de3e4ee620-39b004b2cd.zip
Binary file not shown.
Binary file renamed
BIN
+227 KB
...core-npm-10.3.0-a7ea43c011-4bdeed0f20.zip → ...core-npm-10.3.1-60ec0a24f1-397580c200.zip
Binary file not shown.
Binary file renamed
BIN
+33.4 KB
...ress-npm-10.3.0-f9f204578a-5e802d18f7.zip → ...ress-npm-10.3.1-a128c4678c-cfcffc6ac3.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+15.8 KB
...debug-npm-5.8.1-19c7438d01-a36c3cb11c.zip → ...debug-npm-5.9.1-5ead12191a-ef9daf19c0.zip
Binary file not shown.
Binary file renamed
BIN
+25.3 KB
...gines-npm-5.8.1-0c5500341e-3edc786fee.zip → ...gines-npm-5.9.1-4d1998d255-383d224741.zip
Binary file not shown.
Binary file renamed
BIN
+5.86 KB
...249c3e9a033ebe2-0c53e7214b-cd326d3a0f.zip → ...3de66776b93de64-c7d3f36404-7ed88a87f6.zip
Binary file not shown.
Binary file renamed
BIN
+434 KB
...ngine-npm-5.8.1-0aa40119fb-e2845e5528.zip → ...ngine-npm-5.9.1-ecdef657e6-6a48b323b4.zip
Binary file not shown.
Binary file renamed
BIN
+131 KB
...tform-npm-5.8.1-c5a47f1dea-eb57023cdb.zip → ...tform-npm-5.9.1-9b99c820ee-14e2ba7fcb.zip
Binary file not shown.
Binary file renamed
BIN
+766 KB
...ode-npm-20.11.2-767862562e-029d603b56.zip → ...de-npm-20.11.16-d9bc65d4bc-751f50ec5c.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { GeekController } from '@controllers/geek/geek.ctl'; | ||
import { AccountManagerModule } from '@modules/client/account.module'; | ||
import { Module } from '@nestjs/common'; | ||
import { GeekProvider } from 'providers/news/geek/geek.pvd'; | ||
import { GeekPrismaModule } from './geek-prisma.module'; | ||
|
||
@Module({ | ||
controllers: [GeekController], | ||
imports: [GeekPrismaModule], | ||
imports: [GeekPrismaModule, AccountManagerModule], | ||
providers: [GeekProvider], | ||
}) | ||
export class GeekModule {} |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { HackerController } from '@controllers/hacker/hacker.ctl'; | ||
import { AccountManagerModule } from '@modules/client/account.module'; | ||
import { Module } from '@nestjs/common'; | ||
import { HackersNewsProvider } from 'providers/news/hacker/hacker.pvd'; | ||
import { HackerPrismaModule } from './hacker-prisma.module'; | ||
|
||
@Module({ | ||
controllers: [HackerController], | ||
imports: [HackerPrismaModule], | ||
imports: [HackerPrismaModule, AccountManagerModule], | ||
providers: [HackersNewsProvider], | ||
}) | ||
export class HackerModule {} |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { MachineLearningController } from '@controllers/machine/machine.ctl'; | ||
import { AccountManagerModule } from '@modules/client/account.module'; | ||
import { Module } from '@nestjs/common'; | ||
import { MachineLearningProvider } from 'providers/news/ml/machine.pvd'; | ||
import { MlPrismaModule } from './ml-prisma.module'; | ||
|
||
@Module({ | ||
controllers: [MachineLearningController], | ||
imports: [MlPrismaModule], | ||
imports: [MlPrismaModule, AccountManagerModule], | ||
providers: [MachineLearningProvider], | ||
}) | ||
export class MachineLearningNewsModule {} |
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,157 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { ClientLogger, ManagerLogger } from '@utils/logger.util'; | ||
import { ClientLoginMapItem, ClientLoginMapKey } from 'types/client.type'; | ||
|
||
@Injectable() | ||
export class AccountManager { | ||
private userMap: WeakMap<ClientLoginMapKey, ClientLoginMapItem>; | ||
|
||
private userKeys: Array<ClientLoginMapKey>; | ||
|
||
constructor() { | ||
this.userKeys = []; | ||
this.userMap = new WeakMap(); | ||
} | ||
|
||
public setLoginUser(clientUuid: string, email: string, password?: string) { | ||
const isLogined = this.getItem(clientUuid); | ||
|
||
ManagerLogger.debug('[ACCOUNT] Searching User Info: %o', { | ||
isLogined, | ||
map: this.userMap, | ||
clientUuid, | ||
}); | ||
|
||
if (!isLogined) { | ||
const clientKey = { uuid: clientUuid }; | ||
|
||
this.userKeys.push(clientKey); | ||
this.setItem(email, clientKey, password); | ||
|
||
if (this.userKeys.length >= 5000) { | ||
ClientLogger.debug('[AccountManager] keyList maximum reached. shift()'); | ||
this.userKeys.shift(); | ||
} | ||
|
||
ClientLogger.info('[ACCOUNT] Set Finished'); | ||
|
||
return clientUuid; | ||
} | ||
|
||
ManagerLogger.debug('[ACCOUNT] Found User Key: %o', { | ||
clientUuid, | ||
map: this.userMap, | ||
}); | ||
|
||
const interval = 1000 * 60 * 10; | ||
|
||
const timer = setInterval(() => { | ||
const isExsit = this.getItem(clientUuid); | ||
|
||
if (!isExsit) { | ||
ManagerLogger.info('[ACCOUNT] It is not existing user. Clear Interval.'); | ||
|
||
ManagerLogger.debug('[ACCOUNT] Client Map Inspection: %o', { | ||
isExsit, | ||
clientUuid, | ||
map: this.userMap, | ||
}); | ||
|
||
clearInterval(timer); | ||
} else { | ||
ManagerLogger.info('[ACCOUNT] Expiration time. Delete user.'); | ||
|
||
ManagerLogger.debug('[ACCOUNT] Client Map Inspection: %o', { | ||
clientUuid, | ||
map: this.userMap, | ||
}); | ||
|
||
this.deleteItem(clientUuid); | ||
} | ||
}, interval); | ||
|
||
return clientUuid; | ||
} | ||
|
||
public deleteLogoutUser(clientUuid: string) { | ||
ManagerLogger.debug('[ACCOUNT] Client Data: %o', { | ||
clientUuid, | ||
map: this.userMap, | ||
}); | ||
|
||
const isExist = this.getItem(clientUuid); | ||
|
||
if (!isExist) { | ||
ManagerLogger.info('[ACCOUNT] Not Matchin Data found. Ignore.'); | ||
|
||
return false; | ||
} | ||
|
||
this.deleteItem(clientUuid); | ||
|
||
ManagerLogger.debug('[ACCOUNT] Client Map Delete Inspection: %o', { | ||
clientUuid, | ||
map: this.userMap, | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
public deleteItem(clientUuid: string) { | ||
const index = this.userKeys.findIndex((item) => item.uuid === clientUuid); | ||
|
||
if (index > -1) this.userKeys.splice(index, 1); | ||
|
||
ClientLogger.debug('[ACCOUNT] Delete Finished: %o', { | ||
clientUuid, | ||
index, | ||
keyList: this.userKeys, | ||
map: this.userMap, | ||
}); | ||
} | ||
|
||
public setItem(email: string, clientKey: ClientLoginMapKey, password?: string) { | ||
return this.userMap.set(clientKey, { email, password }); | ||
} | ||
|
||
public getItem(clientUuid: string) { | ||
const key = this.userKeys.find((item) => item.uuid === clientUuid); | ||
|
||
if (!key) return null; | ||
|
||
return this.userMap.get(key) as ClientLoginMapItem; | ||
} | ||
|
||
// public stop() { | ||
// if (this.isListening) { | ||
// this.isListening = false; | ||
|
||
// // Account lock 이 전부 풀릴 때까지 대기 | ||
// for (;;) { | ||
// // 등록된 주소와 mutex 조회 | ||
// const items = this.keyList | ||
// .map((item) => ({ address: item.address, ...this.getItem(item.address) })) | ||
// .filter((item) => item.mutex !== null); | ||
|
||
// // 등록된 주소가 없을 경우 안전하게 끝낼 수 있음 | ||
// if (!items.length) break; | ||
|
||
// // 그렇지 않을 경우 락 여부를 확인해야 함 | ||
// for (let i = 0; i < items.length; i += 1) { | ||
// const item = items[i]; | ||
|
||
// if (item?.mutex?.isLocked()) { | ||
// Logger.info('[AccountManager] Waiting for address in use(locked): %o', item.address); | ||
|
||
// // 1초 대기 | ||
// // SIGTERM 핸들러는 비동기 코드 resolve 가 되지 않으므로 then() 으로 기다림 | ||
// setTimeout(1000).then(() => | ||
// Logger.info ('[AccountManager] Waited 1 second for address: %o', item.address )); | ||
// } | ||
// } | ||
// } | ||
|
||
// TxLogger.info('[AccountManager] Address lock cleared, safe to shutdown.'); | ||
// } | ||
// } | ||
} |
Oops, something went wrong.