Retry on Offline

Another small helpful decorator

I’m getting likes, so I’m assuming they’re helpful to someone :slight_smile:

Here is a nice decorator I use to wrap my client side server calls.

It’s really reduced the amount of AppOfflineError’s my user’s get because of spotty cell service.


from functools import wraps
from anvil_extras import MessagePill

def retry_on_offline(fn):
  @wraps(fn)
  def wrapped(*args,**kwargs):
    attempts = 0
    while attempts < 5:
      try:
        return fn(*args,**kwargs)
      except anvil.server.AppOfflineError as e:
        attempts += 1
        if attempts == 5:
          message = MessagePill.MessagePill(level="error",message = "Application is Offline, You your changes may not save until you get better service.")
          alert(message,title="Warning",large=True)
  return wrapped
5 Likes

Very nice to spot a MessagePill in the wild!

2 Likes

This reminded me of a complimentary approach to managing AppOfflineError more gracefully that I use:

2 Likes