Scheduled script for daily bonuses

In our legacy system we give daily bonuses to players as a background task, that pushes the bonus into their inbox and optionally sends a push notification. During the port to Nakama I’ve created an S2S script to do the same that is externally called by a cron job.

I wonder if scheduled scripts would be better as an internal feature of Nakama.

The bonuses are designed to arrive during a two hour window in the afternoon/early evening based on the player’s location (timezone would also work).

The alternative is to use a third party (OneSignal?) to schedule push notifications. I don’t think this is the right approach for us, for the following reasons.

We can’t rely solely on push as many of our players play in the web browser on desktop, and others have push disabled.

I dislike having the push notifications scheduled externally and the bonus given on login as they can (and will) arrive at different times and cause confusion.

Also we are are currently using Firebase Cloud Messaging which suits our needs but doesn’t support localised scheduling (I don’t know if OneSignal do either).

We are hosting Nakama ourselves, so performance issues are very much our own problem and the script is carefully designed to minimise impact.

@DaveOak This is a great question. Sorry for the slow reply.

The bonuses are designed to arrive during a two hour window in the afternoon/early evening based on the player’s location (timezone would also work).
[…]
We can’t rely solely on push as many of our players play in the web browser on desktop, and others have push disabled.

I’m not sure I understand the inherent link between the prompt to let the player know to collect their daily reward and the grant of the reward itself.

Usually how we handle this in games we’ve worked on and how we know other game teams that use Nakama do is to have the daily reward execute when the app starts as part of the execution of some RPC function or after hook on the player’s GetAccount call.

This has two benefits:

  1. It limits the amount of CPU / IO utilized to grant the daily reward to the player base.

    If you were to execute this as a background job you’d have to process all user accounts and determine whether to skip those that have an outstanding reward to collect. This work is done for a portion of the player base that has already churned out of the game.

  2. You can schedule a local notification or similar to act as the next prompt time for the player which actually eliminates the need for you to schedule a push notification with a remote service. This is a great solution at least for mobile.

Also we are are currently using Firebase Cloud Messaging which suits our needs but doesn’t support localised scheduling (I don’t know if OneSignal do either).

I’m not sure if One Signal supports localized push notifications either but it would give the flexibility to process the event at 7AM local time for the player (or noon or whatever time of day you want to prompt the player).

Sounds to me like your use case needs two fields stored in the use metadata "last_claim_time_unix" and "claim_time_interval_sec". Together you can use these fields to determine whether the daily reward has just occurred for the player and work out how many seconds until the next reward grant (if you decide that some rewards are not daily but after X number of hours).

Hope this helps. Let me know if I’ve missed some other criteria you need for your use case.