Delaying cloud function execution & notifications

4 posts, 1 answers
  1. Arnaud
    Arnaud avatar
    18 posts
    Member since:
    Mar 2016

    Posted 15 Sep Link to this post

    Hello,

    I'm here again with another question regarding your backend solution and more specifically, the execution of cloud code and notifications.

    In our app, each user is able to vote for items with either a "Like" or a "Dislike". Every time a new vote is made on an item, I want to inform the owner of the item that a vote has been made through a notification. This works great.

    However, I want to allow users to make mistake in the sense that if a user unintentionally taps "Dislike" and then reverts his vote right away to "Like", I don't want to send 2 different notifications to the item's owner. The behavior of the Backend should be something like, when a vote is made, wait for a certain duration (lets say 30 seconds) then, send a notification to the item's owner with the current vote.

    I know that I can delay notifications (for the chosen duration) but I believe that the payload must be constructed on creation and that it can not be updated afterwards, am I right? Hence, this is not useful because the Backend can not be sure of the state of the vote 30 seconds after creating the payload.

    The other option would then be to delay the creation of the notification payload. We handle the notification through a cloud function, so is it possible to plan the execution of a cloud function with a certain delay? Obviously, without interfering with the constrain that the cloud function must be run within a 10 second interval to not be canceled (execution timeout).

     

    Thank you very much for your help on this matter and for all the amazing support that you are providing (either here on the forum or by phone call)!

     

    Best.

     

  2. Answer
    Martin
    Admin
    Martin avatar
    67 posts

    Posted 19 Sep Link to this post

    Hi Arnaud,

    I believe scheduling push notifications would be ideal in your case - as you already mentioned you may schedule the notification to be sent on specific time (delayed with 30 sec after the like/dislike is sent) by specifying the NotificationDate in the push notification object fields.

    When the push notification is scheduled but not sent yet, it can be modified (the payload can be changed) or the push notification can even be deleted. Thus in the set time window of 30 sec you can modify the push notification or delete it.

    To modify its content you can make a PUT request to the following endpoint:

    http://api.everlive.com/v1/your-app-id/Push/Notifications/push-notification-id

    The push-notification-id would be returned when you create and schedule the push notification in the first place. In the body of the request you would put the modified notification fields. For this request you will need your MasterKey as Authorization header or as you are using Cloud function you can create an Everlive instance with Master Key authorization using Everlive.Sdk.withMasterKey().

    To delete the push notification you would make a DELETE request to the same endpoint.

    I would suggest to increase the time frame from 30 sec to 1 or 2 min in order to allow more time for the notification to be changed just in case (as the internet connection might be poor for example).

    Let me know if this has worked in your case.


    Regards,
    Martin
    Telerik by Progress
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  3. Arnaud
    Arnaud avatar
    18 posts
    Member since:
    Mar 2016

    Posted 19 Sep in reply to Martin Link to this post

    Thank you very much! It is exactly what I was looking for.

    I was thinking that the notification could not be changed or deleted after being scheduled. Perfect!

    Best

  4. Martin
    Admin
    Martin avatar
    67 posts

    Posted 21 Sep Link to this post

    Hi,

    I am glad to hear this has worked out.

    Regards,
    Martin
    Telerik by Progress
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
Back to Top