Ring-ring call alert, and workload units in 'do every 5 seconds' action

I want to repeat a ‘ring’ sound every couple of seconds, to alert the user of an incoming voice call. What’s the best way to do it? I currently do a database search to check if the current user has an unanswered call:

This plays the alert just once. I can repeat it using a ‘do every 5 seconds’ action, but I assume this is a costly use of workload units.

Are there any good practices for repeating a sound while a server side condition is true?

Yes thats very correct. Running a ‘Do every 5 seconds’ containing a search on every active user is a recipe for destruction.

A better approach would be to create ‘Conversation’ field on the user.
When a conversation is activated/created, set the receiver’s field to the active conversation.
When a conversation is answered/cancelled/failed, set the receiver’s field to empty.
On the page, add a ‘Do when condition is true’ workflow that triggers when the current user’s conversation is not empty. This will start playing the sound. You can use ping-pong custom events to keep the loop going while the conversation is still active (ie the field is not empty).
Ping pong custom events are two custom events which schedule each other while a condition is true; Custom event A schedules Custom event B in X seconds, and Custom event B schedules Custom event A in X seconds. Remember to put the conditional in both scheduling actions.

This approach consumes minimal WU, as it leverages Bubble’s native web socket. However what happens if the user leaves the page? How do you handle this?

2 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.