I want my Django app to check daily at 11:00 if I made a record, and if not - to ‘beep’ me that it’s time to make a record. I’m totally new to all these things so I need a lot of help.
As I understand there are 2 things that I need to build (and I have no idea how).
- some kind of a crone job that will run a script. (check if I didn’t forget to make my morning record, and to ‘wake me up’ if necessary).
- some kind of a push notification system that will reload a page so a notification would produce a sound?
Please push me in a right direction.
The first is easy and common, the second is not possible from the server.
Yes, a cron job is the easiest way to schedule something to be run on a periodic basis. (A web search for “creating a cron job” will help you find resources for this.) I’d suggest making this a custom manage command.
The server has no ability to force the client browser to load a page, in the absence of an existing connection. For the server to initiate any communication, the browser would already need to be open and connected to your site with a websocket connection. This implies having JavaScript on a page that is running and communicating with the server and waiting for the server to send it a notification.
1 Like
Thanks for your quick reply with information.
I barely understand those docs, but it looks like the second can by done by creating with Django a PWA app and using ‘notifications API’. Notifications API - Web APIs | MDN
Or I misunderstand?
Oops, I forgot that on mobile I logged in as a different user then on my computer. Sorry.
You don’t misunderstand - however, it does require that the browser / service worker be running. If your browser is closed, you will not receive a notification. (All the PWA does is disconnect the service worker from the context of a single tab - it’s still a process that needs to be running.)
1 Like
I don’t quite understand the hole meaning of those geeky words, but they sound like it can be done with Django app.
Also I just red the ‘what is pwa’ you posted in neighbour thread and it confirms:
" * Respond to push messages from the server.
I’ll start from learning how to crate a crone job, and when done, will move to this notification thingy.
Thanks again for help.
The point I was trying to make is perhaps better described here: Push notifications FAQ
If the main objective is “get a notification”, and not necessarily “get a notification from a web browser” there are other options.
If you have a custom Django management command running via cron, you could have it generate a notification directly, maybe:
- Using something like Twilio to send an SMS message.
- Sending a notification to a Slack channel, and setting Slack up to send you an alert when such a message is received. (Probably only useful if you’re already using Slack.)
- I expect there are other similar services that it’s possible to notify using Python
you mean an app have to be running (not closed) for being able ‘to notify’ me? If so it is not a problem at all for me.
Thanks. It looks like the “do not close pwa if you want to be notified” is the easiest (and thus the best) way for me.
I created a custom manage command. It was eazy indeed.
Now I’m ready to move to the second part - push notifications. And I have a question - is there some Django module/library for those service workers/push messages from the server? Or I should read and implement those things from pwa documentation?
Personally, I don’t have any direct knowledge or experience in that area. I suggest you search pypi.org and djangopackages.com for likely candidates.
1 Like
Thanks! I’ll try to find it there.
I don’t know. I don’t have any direct experience or knowledge in this area. It looks a little old, so it may need some work to be made current.
1 Like
Thanks. I understand.
The last question on this topic if I may.
May be it will be the smarter to build a native app (and easier) if I want my app to notify/alarm me?
I read in the other topic the question “why do you decided to use Django (technology for building web apps) for this?” Is this question valid for my case too?
That is a question that is always valid, and the answer to it frequently depends upon non-technical issues.
1 Like