Skip to content

Commit

Permalink
db connection close 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
soyoon247 committed Sep 26, 2023
1 parent 77a4e2d commit fd1e872
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions currencies/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime

import requests
from django import db

from calculator.utils import send_slack
from currencies.models import Currency
Expand All @@ -20,7 +21,9 @@ def get_currency(self):
return res.json()

def execute(self):

try:
db.close_old_connections()
if self._currency_auth_key is None:
print("currency auth key required!")
return
Expand All @@ -37,6 +40,7 @@ def execute(self):
cur_unit=currency.get("cur_unit").split("(")[0],
defaults=update_dict
)
db.connections.close_all()
except Exception as e:
err_msg = traceback.format_exc()
send_slack(f":ghost: [FAILED] [SCHEDULE] [CURRENCY] *{e}* {err_msg}")
Expand Down
4 changes: 4 additions & 0 deletions hotels/services/schedule_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from datetime import date, datetime
from statistics import mean, median

from django import db

from calculator.utils import send_slack
from cities.models import City
from hotels.models import HotelPrice
Expand Down Expand Up @@ -40,10 +42,12 @@ def _update_hotel_price(

def execute(self):
try:
db.close_old_connections()
cities = City.objects.all()
target_date = datetime.today()
for city in cities:
self._update_hotel_price(city.city_code, target_date)
db.connections.close_all()

except Exception as e:
err_msg = traceback.format_exc()
Expand Down

0 comments on commit fd1e872

Please sign in to comment.