Skip to content

Commit

Permalink
fix: celery, asgi 각각 초기화
Browse files Browse the repository at this point in the history
  • Loading branch information
leehjhjhj committed Aug 17, 2023
1 parent b84c7f3 commit 9161f3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 7 additions & 1 deletion call/models/assign_signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from firebase_admin import messaging
import firebase_admin

def websocket_message(instance, created: bool):
from . import Assign
Expand Down Expand Up @@ -55,5 +56,10 @@ def send_push_notification(instance):
},
token=registration_token,
)
response = messaging.send(message)
if instance.status == "failed":
app = firebase_admin.get_app('celery_app')
else:
app = firebase_admin.get_app('asgi_app')

response = messaging.send(message, app=app)
print('Successfully sent message:', response)
3 changes: 1 addition & 2 deletions hackathon/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

cred_path = config("FIRE_BASE_JSON_KEY_PATH")
cred = credentials.Certificate(cred_path)
if not firebase_admin._apps:
firebase_admin.initialize_app(cred)
firebase_admin.initialize_app(cred, name='asgi_app')

django_asgi_app = get_asgi_application()

Expand Down
3 changes: 1 addition & 2 deletions hackathon/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

cred_path = config("FIRE_BASE_JSON_KEY_PATH")
cred = credentials.Certificate(cred_path)
if not firebase_admin._apps:
firebase_admin.initialize_app(cred)
firebase_admin.initialize_app(cred, name='celery_app')

#테스트할 때만 주석해제하고 실제로 배포할 때는 주석처리하기
#@app.task(bind=True, ignore_result=True)
Expand Down

0 comments on commit 9161f3f

Please sign in to comment.