Skip to content

Commit 6ff04db

Browse files
committed
πŸ› fix: ν”Όλ“œ 크둀러 νƒ€μž„ λ”œλ ˆμ΄ 제거
1 parent 282e90d commit 6ff04db

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

β€Žfeed-crawler/src/common/parser/base-feed-parser.tsβ€Ž

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ export abstract class BaseFeedParser {
2727
this.parserUtil = parserUtil;
2828
}
2929

30-
async parseFeed(rssObj: RssObj, xmlData: string): Promise<FeedDetail[]> {
30+
async parseFeed(
31+
rssObj: RssObj,
32+
xmlData: string,
33+
startTime: Date,
34+
): Promise<FeedDetail[]> {
3135
// 각 포맷(atom1.0, rss2.0 λ“±...)
3236
const rawFeeds = this.extractRawFeeds(xmlData);
33-
const timeMatchedFeeds = this.filterByTime(rawFeeds);
37+
const timeMatchedFeeds = this.filterByTime(rawFeeds, startTime);
3438
const detailedFeeds = await this.convertToFeedDetails(
3539
rssObj,
3640
timeMatchedFeeds,
@@ -42,8 +46,8 @@ export abstract class BaseFeedParser {
4246
abstract canParse(xmlData: string): boolean;
4347
protected abstract extractRawFeeds(xmlData: string): RawFeed[];
4448

45-
private filterByTime(rawFeeds: RawFeed[]): RawFeed[] {
46-
const now = new Date().setSeconds(0, 0);
49+
private filterByTime(rawFeeds: RawFeed[], startTime: Date): RawFeed[] {
50+
const now = new Date(startTime).setSeconds(0, 0);
4751
return rawFeeds.filter((item) => {
4852
const pubDate = new Date(item.pubDate).setSeconds(0, 0);
4953
const timeDiff = (now - pubDate) / (ONE_MINUTE * TIME_INTERVAL);

β€Žfeed-crawler/src/common/parser/feed-parser-manager.tsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class FeedParserManager {
1717
this.parsers = [rss20Parser, atom10Parser];
1818
}
1919

20-
async fetchAndParse(rssObj: RssObj): Promise<FeedDetail[]> {
20+
async fetchAndParse(rssObj: RssObj, startTime: Date): Promise<FeedDetail[]> {
2121
try {
2222
const response = await fetch(rssObj.rssUrl, {
2323
headers: {
@@ -38,7 +38,7 @@ export class FeedParserManager {
3838
}
3939
logger.info(`${rssObj.blogName}: ${parser.constructor.name} μ‚¬μš©`);
4040

41-
return await parser.parseFeed(rssObj, xmlData);
41+
return await parser.parseFeed(rssObj, xmlData, startTime);
4242
} catch (error) {
4343
logger.warn(`[${rssObj.rssUrl}] ν”Όλ“œ νŒŒμ‹± 쀑 였λ₯˜ λ°œμƒ: ${error}`);
4444
return [];

β€Žfeed-crawler/src/feed-crawler.tsβ€Ž

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ export class FeedCrawler {
1717
private readonly feedParserManager: FeedParserManager,
1818
) {}
1919

20-
async start() {
20+
async start(startTime: Date) {
2121
logger.info('==========μž‘μ—… μ‹œμž‘==========');
22-
const startTime = Date.now();
2322

2423
await this.feedRepository.deleteRecentFeed();
2524

@@ -29,7 +28,7 @@ export class FeedCrawler {
2928
return;
3029
}
3130

32-
const newFeedsByRss = await this.feedGroupByRss(rssObjects);
31+
const newFeedsByRss = await this.feedGroupByRss(rssObjects, startTime);
3332
const newFeeds = newFeedsByRss.flat();
3433

3534
if (!newFeeds.length) {
@@ -44,19 +43,22 @@ export class FeedCrawler {
4443
await this.feedRepository.setRecentFeedList(insertedData);
4544

4645
const endTime = Date.now();
47-
const executionTime = endTime - startTime;
46+
const executionTime = endTime - startTime.getTime();
4847

4948
logger.info(`μ‹€ν–‰ μ‹œκ°„: ${executionTime / 1000}seconds`);
5049
logger.info('==========μž‘μ—… μ™„λ£Œ==========');
5150
}
5251

53-
private feedGroupByRss(rssObjects: RssObj[]): Promise<FeedDetail[][]> {
52+
private feedGroupByRss(
53+
rssObjects: RssObj[],
54+
startTime: Date,
55+
): Promise<FeedDetail[][]> {
5456
return Promise.all(
5557
rssObjects.map(async (rssObj: RssObj) => {
5658
logger.info(
5759
`${rssObj.blogName}(${rssObj.rssUrl}) μ—μ„œ 데이터 μ‘°νšŒν•˜λŠ” 쀑...`,
5860
);
59-
return await this.feedParserManager.fetchAndParse(rssObj);
61+
return await this.feedParserManager.fetchAndParse(rssObj, startTime);
6062
}),
6163
);
6264
}

β€Žfeed-crawler/src/main.tsβ€Ž

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import './common/env-load';
33
import logger from './common/logger';
44
import { FeedCrawler } from './feed-crawler';
55
import { container } from './container';
6-
import { RssRepository } from './repository/rss.repository';
7-
import { FeedRepository } from './repository/feed.repository';
86
import { DEPENDENCY_SYMBOLS } from './types/dependency-symbols';
97
import { DatabaseConnection } from './types/database-connection';
108
import { ClaudeService } from './claude.service';
119
import * as schedule from 'node-schedule';
1210
import { RedisConnection } from './common/redis-access';
13-
import { TagMapRepository } from './repository/tag-map.repository';
1411

1512
function initializeDependencies() {
1613
return {
@@ -31,8 +28,9 @@ function registerSchedulers(
3128
dependencies: ReturnType<typeof initializeDependencies>,
3229
) {
3330
schedule.scheduleJob('FEED CRAWLING', '0,30 * * * *', async () => {
34-
logger.info(`Feed Crawling Start: ${new Date().toISOString()}`);
35-
dependencies.feedCrawler.start();
31+
const now = new Date();
32+
logger.info(`Feed Crawling Start: ${now.toISOString()}`);
33+
dependencies.feedCrawler.start(now);
3634
});
3735

3836
schedule.scheduleJob(

0 commit comments

Comments
Β (0)