You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to implement a notification features which notify the user every selected day of a week at a specific selected time. I use celery, redis, firebase for this task.
When I create a productivity instance, everything is fine and the fcm token are also stored to user table in the database. Celery worker and beat didn't output any error.
However, I never got notification.
The logs of celery worker :
I am trying to implement a notification features which notify the user every selected day of a week at a specific selected time. I use celery, redis, firebase for this task.
My backend (Django):
pms_backend (main app or the default one):
settings.py:
celery.py (same directory as settings.py) :
internal_services (another app):
tasks.py:
c```
red = credentials.Certificate(os.path.join(settings.BASE_DIR, 'firebase.json'))
firebase_admin.initialize_app(cred)
@shared_task
def send_push_notification(title, body, user_tokens):
message = messaging.MulticastMessage(
notification=messaging.Notification(
title=title,
body=body
),
tokens=user_tokens
)
try:
response = messaging.send_multicast(message)
print('Successfully sent message:', response)
except Exception as e:
print('Error sending message:', e)
class ProductivityModeView(generics.CreateAPIView):
serializer_class = Productivity
permission_classes = [IsAuthenticated]
importScripts('https://www.gstatic.com/firebasejs/10.1.0/firebase-app-compat.js')
importScripts('https://www.gstatic.com/firebasejs/10.1.0/firebase-messaging-compat.js')
firebase.initializeApp({
apiKey: "AIzaSyD6na5iVJPYZdFGRB79iKIwMdpBKxDLowg",
authDomain: "aqueous-thought-426115-i6.firebaseapp.com",
projectId: "aqueous-thought-426115-i6",
storageBucket: "aqueous-thought-426115-i6.appspot.com",
messagingSenderId: "505424754285",
appId: "1:505424754285:web:d99417903cef886f36b164",
measurementId: "G-W4LKDCL06Y"
});
const messaging = firebase.messaging();
messaging.onBackgroundMessage((payload) => {
console.log('Received background message ', payload);
const notificationTitle = payload.notification.title;
const notificationOptions = {
body: payload.notification.body,
};
});
`
const ProductivityModeForm = () => {
const vapidKey = 'BPQqDxdT7jRvEXZFNvgTNn355V3hLx4OAX78s7aDiiWO6RGzyxkBv5vD4eEMzOYK6Btywn6uOQyQ3Pkbequfi90';
const [productivityConfig, setProductivityConfig] = useState({
start_time: '',
end_time: '',
selected_day: []
});
};
export default ProductivityModeForm;
celery -A pms_backend worker -l info
-------------- celery@Zonunmawias-MacBook-Air.local v5.3.6 (emerald-rush)
--- ***** -----
-- ******* ---- macOS-10.16-x86_64-i386-64bit 2024-06-19 16:37:23
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** -----
-------------- [queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. internal_services.tasks.send_push_notification
[2024-06-19 16:37:24,916: INFO/MainProcess] Connected to redis://localhost:6379/0
[2024-06-19 16:37:24,916: WARNING/MainProcess]
[2024-06-19 16:37:24,919: INFO/MainProcess] mingle: searching for neighbors
[2024-06-19 16:37:25,944: INFO/MainProcess] mingle: all alone
[2024-06-19 16:37:25,971: INFO/MainProcess] celery@Zonunmawias-MacBook-Air.local ready.
celery -A pms_backend beat -l info
celery beat v5.3.6 (emerald-rush) is starting.
__ - ... __ - _
LocalTime -> 2024-06-19 16:37:37
Configuration ->
. broker -> redis://localhost:6379/0
. loader -> celery.loaders.app.AppLoader
. scheduler -> celery.beat.PersistentScheduler
. db -> celerybeat-schedule
. logfile -> [stderr]@%INFO
. maxinterval -> 5.00 minutes (300s)
[2024-06-19 16:37:37,614: INFO/MainProcess] beat: Starting...
The text was updated successfully, but these errors were encountered: