-
Notifications
You must be signed in to change notification settings - Fork 2
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 #2 from boostcampwm-2024/refactor/feed-crawler-oop
♻️ refactor: FeedCrawler OOP 적용
- Loading branch information
Showing
10 changed files
with
93 additions
and
33 deletions.
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 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,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 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,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 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,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 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 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"), | ||
RssRepository: Symbol.for("RssRepository"), | ||
FeedRepository: Symbol.for("FeedRepository"), | ||
} |