-
Notifications
You must be signed in to change notification settings - Fork 1
♻️ refactor: FeedCrawler OOP 적용 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
68b3d9a
📦 chore: tsyringe 라이브러리 설치
asn6878 dde5c74
♻️ refactor: db 커넥션 인터페이스 작성
asn6878 183e562
♻️ refactor: di container 사용 시 사용할 심볼 선언
asn6878 15e4869
♻️ refactor: 컨테이너 생성 및 사용할 클래스들 설정
asn6878 e1da3e1
♻️ refactor: feedCrawler.ts 에 변경사항 적용 및 메인 함수명 변경
asn6878 90ce05d
📦 chore: reflect-metadata 라이브러리 설치
asn6878 51e5a54
♻️ refactor: 의존성 DI Container에서 받아쓰도록 설정
asn6878 c499909
♻️ refactor: mysqlConection 싱글톤 객체로 DI 주입
asn6878 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| import { container } from "tsyringe"; | ||
| import { DatabaseConnection } from "./types/database-connection"; | ||
| import { DEPENDENCY_SYMBOLS } from "./types/dependency-symbols"; | ||
| import {MySQLConnection} from "./common/mysql-access"; | ||
| import {RssRepository} from "./repository/rss.repository"; | ||
| import {FeedRepository} from "./repository/feed.repository"; | ||
|
|
||
| container.registerSingleton<DatabaseConnection>(DEPENDENCY_SYMBOLS.DatabaseConnection, MySQLConnection); | ||
|
|
||
| container.registerSingleton<RssRepository>(DEPENDENCY_SYMBOLS.RssRepository, RssRepository); | ||
| container.registerSingleton<FeedRepository>(DEPENDENCY_SYMBOLS.FeedRepository, FeedRepository); | ||
|
|
||
| export { container }; |
This file contains hidden or 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 hidden or 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,16 +1,29 @@ | ||
| import "reflect-metadata"; | ||
| import logger from "./common/logger.js"; | ||
| import { feedCrawler } from "./feed-crawler.js"; | ||
| import { mysqlConnection } from "./common/mysql-access.js"; | ||
| import { FeedCrawler } from "./feed-crawler.js"; | ||
| import { container } from "./container"; | ||
| import {RssRepository} from "./repository/rss.repository"; | ||
| import {FeedRepository} from "./repository/feed.repository"; | ||
| import {DEPENDENCY_SYMBOLS} from "./types/dependency-symbols"; | ||
| import {DatabaseConnection} from "./types/database-connection"; | ||
|
|
||
| async function runCrawler() { | ||
| async function main() { | ||
| logger.info("==========작업 시작=========="); | ||
| const startTime = Date.now(); | ||
|
|
||
| const rssRepository = container.resolve<RssRepository>(DEPENDENCY_SYMBOLS.RssRepository); | ||
| const feedRepository = container.resolve<FeedRepository>(DEPENDENCY_SYMBOLS.FeedRepository); | ||
| const dbConnection = container.resolve<DatabaseConnection>(DEPENDENCY_SYMBOLS.DatabaseConnection); | ||
|
|
||
| const feedCrawler = new FeedCrawler(rssRepository, feedRepository); | ||
| await feedCrawler.start(); | ||
|
|
||
| const endTime = Date.now(); | ||
| const executionTime = endTime - startTime; | ||
| await mysqlConnection.end(); | ||
|
|
||
| await dbConnection.end(); | ||
| logger.info(`실행 시간: ${executionTime / 1000}seconds`); | ||
| logger.info("==========작업 완료=========="); | ||
| } | ||
|
|
||
| runCrawler(); | ||
| main(); |
This file contains hidden or 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 hidden or 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,12 +1,15 @@ | ||
| import { mysqlConnection } from "../common/mysql-access"; | ||
| import { RssObj } from "../common/types"; | ||
| import { DatabaseConnection } from "../types/database-connection"; | ||
| import { DEPENDENCY_SYMBOLS } from "../types/dependency-symbols"; | ||
| import { inject, injectable } from "tsyringe"; | ||
|
|
||
| @injectable() | ||
| export class RssRepository { | ||
| constructor(@inject(DEPENDENCY_SYMBOLS.DatabaseConnection) private readonly dbConnection: DatabaseConnection) {}; | ||
|
|
||
| class RssRepository { | ||
| public async selectAllRss(): Promise<RssObj[]> { | ||
| const query = `SELECT id, rss_url as rssUrl, name as blogName, blog_platform as blogPlatform | ||
| FROM rss_accept`; | ||
| return mysqlConnection.executeQuery(query); | ||
| return this.dbConnection.executeQuery(query, []); | ||
| } | ||
| } | ||
|
|
||
| export const rssRepository = new RssRepository(); | ||
This file contains hidden or 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,4 @@ | ||
| export interface DatabaseConnection { | ||
| executeQuery<T>(query: string, params: any[]): Promise<T[]>; | ||
| end(): Promise<void>; | ||
| } |
This file contains hidden or 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,5 @@ | ||
| export const DEPENDENCY_SYMBOLS = { | ||
| DatabaseConnection: Symbol.for("DatabaseConnection"), | ||
asn6878 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| RssRepository: Symbol.for("RssRepository"), | ||
| FeedRepository: Symbol.for("FeedRepository"), | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.