Skip to content

Commit

Permalink
Merge pull request #28 from 2jun0/GDET-42
Browse files Browse the repository at this point in the history
GDET-42: 람다 빌드 및 배포 V2
  • Loading branch information
2jun0 authored Feb 8, 2024
2 parents 36e5b04 + 9c492b5 commit d24b27f
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 158 deletions.
3 changes: 2 additions & 1 deletion aws_lambdas/daily_quiz/aws_lambda/lambda_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ def save_quizzes(self, quizzes: Iterable[SaveQuiz]):

def get_all_games(self) -> list[Game]:
event = Event(name="get_all_games", payload=None)
return self.invoke_lambda(event)
res = self.invoke_lambda(event)
return [Game(**g) for g in res]
20 changes: 10 additions & 10 deletions aws_lambdas/daily_quiz/lambda_func.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from typing import Any

from . import protocols
from .aws_lambda.lambda_api import LambdaAPI
from .daily_quiz.serivce import new_daily_quizzes as new_daily_quizzes_
from .logger import logger
from .steam.steam_api import SteamAPI

def lambda_handler(event: Any, context: Any):

def new_daily_quizzes(lambda_api: protocols.LambdaAPI, steam_api: protocols.SteamAPI):
logger.info("-- new daily quizzes job start --")
from daily_quiz import protocols
from daily_quiz.aws_lambda.lambda_api import LambdaAPI
from daily_quiz.daily_quiz.serivce import new_daily_quizzes as new_daily_quizzes_
from daily_quiz.logger import logger
from daily_quiz.steam.steam_api import SteamAPI

new_daily_quizzes_(lambda_api, steam_api)
def new_daily_quizzes(lambda_api: protocols.LambdaAPI, steam_api: protocols.SteamAPI):
logger.info("-- new daily quizzes job start --")

logger.info("-- new daily quizzes job end --")
new_daily_quizzes_(lambda_api, steam_api)

logger.info("-- new daily quizzes job end --")

def lambda_handler(event: Any, context: Any):
lambda_api = LambdaAPI()
steam_api = SteamAPI()

Expand Down
44 changes: 22 additions & 22 deletions aws_lambdas/database_lambda/lambda_func.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from typing import Any, Callable

from sqlalchemy.orm import Session

from database_lambda.database import engine, init_database
from database_lambda.event import Event, EventName
from database_lambda.game.service import get_all_games, save_games
from database_lambda.logger import logger
from database_lambda.screenshot.service import save_screenshots
def lambda_handler(event: Any, context: Any):

funcs: dict[EventName, Callable[..., Any]] = {
"save_games": save_games,
"save_screenshots": save_screenshots,
"get_all_games": get_all_games,
}
from sqlalchemy.orm import Session

from database_lambda.database import engine
from database_lambda.event import Event, EventName
from database_lambda.game.service import get_all_games, save_games
from database_lambda.logger import logger
from database_lambda.quiz.service import save_quizzes
from database_lambda.screenshot.service import save_screenshots

def handle_event(session: Session, event: Event) -> Any:
func = funcs[event["name"]]
funcs: dict[EventName, Callable[..., Any]] = {
"save_games": save_games,
"save_screenshots": save_screenshots,
"get_all_games": get_all_games,
"save_quizzes": save_quizzes,
}

if "payload" in event:
result = func(session, event["payload"])
else:
result = func(session)

session.commit()
return result
def handle_event(session: Session, event: Event) -> Any:
func = funcs[event["name"]]

if "payload" in event and event["payload"]:
result = func(session, event["payload"])
else:
result = func(session)

def lambda_handler(event: Event, context: Any):
init_database()
session.commit()
return result

logger.info("Handle event [required event is %s]", event)

Expand Down
19 changes: 9 additions & 10 deletions aws_lambdas/game_updater/lambda_func.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from typing import Any

from game_updater.aws_lambda.lambda_api import LambdaAPI
from game_updater.logger import logger
from game_updater.scraper.service import scrap_games
from game_updater.steam.steam_api import SteamAPI

def lambda_handler(event: Any, context: Any):

def scrap_games_job(lambda_api: LambdaAPI):
logger.info("-- scrap game job start -- ")
from game_updater.aws_lambda.lambda_api import LambdaAPI
from game_updater.logger import logger
from game_updater.scraper.service import scrap_games
from game_updater.steam.steam_api import SteamAPI

scrap_games(SteamAPI(), lambda_api)
def scrap_games_job(lambda_api: LambdaAPI):
logger.info("-- scrap game job start -- ")

logger.info("-- scrap game job end -- ")
scrap_games(SteamAPI(), lambda_api)

logger.info("-- scrap game job end -- ")

def lambda_handler(event: Any, context: Any):
lambda_api = LambdaAPI()

scrap_games_job(lambda_api)
Loading

0 comments on commit d24b27f

Please sign in to comment.