Skip to content

Commit

Permalink
세션 주입방식 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
stopmin committed Jul 12, 2024
1 parent 6baefba commit 2fc9179
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/service/news_scheduling_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlalchemy.ext.asyncio import AsyncSession

from app.config.loguru_config import logger
from app.database.session import get_db_session
from app.database.session import db_session
from app.model.article_publisher import Publisher
from app.service.article_manage_service import ArticleManageService
from app.service.simple_article_service import generate_simple_article
Expand Down Expand Up @@ -55,9 +55,14 @@ async def fetch_and_store_all_publisher_feeds():

async def run_crawl_and_store(session: AsyncSession):
articles = await fetch_and_store_all_publisher_feeds()

# 기존에 저장된 기사들을 가져옴
exist_articles = await ArticleManageService().get_all_articles(session=session)

# 기존에 저장된 기사들의 URL을 가져옴
exist_urls = {article.url for article in exist_articles}

# 새로운 기사들만 필터링
new_articles = [
article for article in articles if article["link"] not in exist_urls
]
Expand All @@ -69,7 +74,7 @@ async def run_crawl_and_store(session: AsyncSession):
)
for article in new_articles
]
await asyncio.gather(*tasks)
await asyncio.gather(*tasks, return_exceptions=True)
else:
logger.info("No new articles")

Expand All @@ -83,7 +88,7 @@ async def schedule_task():
delay = (target_time - now).total_seconds()
await asyncio.sleep(delay)

async with get_db_session() as session: # pylint: disable=not-async-context-manager
async with db_session() as session:
await run_crawl_and_store(session)


Expand Down

0 comments on commit 2fc9179

Please sign in to comment.