Skip to content

Commit

Permalink
Merge pull request #46 from QRTaxi/hjNewPush
Browse files Browse the repository at this point in the history
fix: failed 푸시 알람을 위한 celery firebase 초기화
  • Loading branch information
leehjhjhj authored Aug 17, 2023
2 parents 5d28d49 + 9161f3f commit 2956a51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 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)
2 changes: 1 addition & 1 deletion hackathon/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

django_asgi_app = get_asgi_application()

Expand Down
7 changes: 7 additions & 0 deletions hackathon/celery.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import os
from celery import Celery
import firebase_admin
from firebase_admin import credentials
from decouple import config

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hackathon.settings.prod')

Expand All @@ -8,6 +11,10 @@

app.autodiscover_tasks()

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

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

0 comments on commit 2956a51

Please sign in to comment.