Scheduled events - sending notifications at a specified time by a user

Hello.
I’m creating an application which sends push notification to users.

I’d like to have the application send notification at the specified time by a user, but I don’t know how to implement it in phoenix…
I only thought out a way of generating a process by Task.async and run Process.sleep until the specified time. I’m not sure the process is in proper way though :sweat_smile:

Thank you.

1 Like

Have you tried Oban? I think it has scheduling function.

1 Like

I’ll check it, thanks!

To give a little more detail, if you go for a pure Process way, you can either do Task.async & Process.sleep or you can do Process.send_after, but that is not a good way to do things.

This is because Process are ephemeral, when you restart your app your scheduled Process is gone, so your users won’t receive anything. The logical solution to an ephemeral problem is to add persistence, and that’s where things like Oban comes in, it stores the state in the DB so it works across restarts.

Another thing you want to keep in mind is user timezone - if a user specified at 2pm of CEST, you need to calculate the offset correctly so you can work across DST. This has an implication on how you schedule your jobs, for example don’t calculate the scheduled_at upfront because times change, maybe you want to have a cron job that check user’s configuration instead.

4 Likes

There is also something like Quantum or Periodic

You can’t go wrong with Oban, but without a database or if you can’t use PostgreSQL, you might take a look at these two.

2 Likes

Thank you! I’ll check them as well!