Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
brainCloud Forums
  1. Home
  2. Suggestions
  3. Portal-X Suggestions
  4. Repeat push notification schedule

Repeat push notification schedule

Scheduled Pinned Locked Moved Portal-X Suggestions
4 Posts 3 Posters 1.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LEE JONG GUN
    wrote on last edited by
    #1

    Currently, we are repeating push notifications by scheduling cloud codes 24 hours later with push notifications to repeat them at a set time every day for a specific segment.

    The problem with this method is that the time gradually gets later due to server delays.

    Also, there was an issue a while ago where calls were suddenly made at a time other than 24 hours due to a server error.

    It would be nice to have a function that can repeat at a set time (UTC) rather than after N hours.

    1 Reply Last reply
    0
    • Paul WinterhalderP Offline
      Paul WinterhalderP Offline
      Paul Winterhalder
      brainCloudAdmin
      wrote on last edited by
      #2

      Hi Lee,

      We hear you. I'll raise it with the devs.

      Paul.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JasonL
        bitHeads
        wrote on last edited by
        #3

        You can schedule a cloud code script to run at a specific target time (as shown in the example below, which will execute at 23:59 every day), instead of adding a certain amount of time to the script's execution time.

        "use strict";
        
        function main() {
            var response = {}
        
            bridge.logDebugJson("Script Inputs", data)
        
            const scriptName = data.scriptName
            const interval = data.args.interval
            const searchSpan = interval < 60 ? 60 : 60 * 24
        
            // schedule checking and re-schedule itself for the next week at 23:59 on the same day
            var scriptProxy = bridge.getScriptServiceProxy()
        
            var dateTimeSpanMinsFromNowInMillis = new Date().getTime() + (searchSpan * 60 * 1000)
            var result = scriptProxy.getScheduledCloudScripts(dateTimeSpanMinsFromNowInMillis)
        
            var nowTime = new Date().getTime()
        
            if ((result.status == 200) && (result.data !== null)) {
                for (var i = 0; i < result.data.scheduledJobs.length; i++) {
                    if (result.data.scheduledJobs[i].scriptName === scriptName && result.data.scheduledJobs[i].scheduledStartTime > nowTime) {
                        scriptProxy.cancelScheduledScript(result.data.scheduledJobs[i].jobId)
                    }
                }
            }
        
            const targetHour = 23
            const targetMinute = 59
            const minutesDifference = getMinutesDifference(targetHour, targetMinute)
            let minutesFromNow = minutesDifference + interval
            bridge.logInfo(`minutesFromNow between the script calling time and the time of 23:59 on a same day${minutesFromNow}`)
            response.scheduleJob = scriptProxy.scheduleRunScriptMinutes(scriptName, data, minutesFromNow)
        
            // the code for your script 
        
            return response
        }
        
        function getMinutesDifference(targetHour, targetMinute) {
            const now = new Date()
            const targetTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), targetHour, targetMinute)
            const differenceInMilliseconds = targetTime - now
            bridge.logInfo(`differenceInMilliseconds between the script calling time and the target time: ${differenceInMilliseconds}`)
            const differenceInMinutes = Math.floor(differenceInMilliseconds / (1000 * 60))
            return differenceInMinutes
        }
        
        main()
        

        The parameters for this script will be 1440 minutes,

        {
          "scriptName": "thisScriptNameItself",
          "args": {
            "interval": 1440
          }
        }
        
        L 1 Reply Last reply
        0
        • J JasonL

          You can schedule a cloud code script to run at a specific target time (as shown in the example below, which will execute at 23:59 every day), instead of adding a certain amount of time to the script's execution time.

          "use strict";
          
          function main() {
              var response = {}
          
              bridge.logDebugJson("Script Inputs", data)
          
              const scriptName = data.scriptName
              const interval = data.args.interval
              const searchSpan = interval < 60 ? 60 : 60 * 24
          
              // schedule checking and re-schedule itself for the next week at 23:59 on the same day
              var scriptProxy = bridge.getScriptServiceProxy()
          
              var dateTimeSpanMinsFromNowInMillis = new Date().getTime() + (searchSpan * 60 * 1000)
              var result = scriptProxy.getScheduledCloudScripts(dateTimeSpanMinsFromNowInMillis)
          
              var nowTime = new Date().getTime()
          
              if ((result.status == 200) && (result.data !== null)) {
                  for (var i = 0; i < result.data.scheduledJobs.length; i++) {
                      if (result.data.scheduledJobs[i].scriptName === scriptName && result.data.scheduledJobs[i].scheduledStartTime > nowTime) {
                          scriptProxy.cancelScheduledScript(result.data.scheduledJobs[i].jobId)
                      }
                  }
              }
          
              const targetHour = 23
              const targetMinute = 59
              const minutesDifference = getMinutesDifference(targetHour, targetMinute)
              let minutesFromNow = minutesDifference + interval
              bridge.logInfo(`minutesFromNow between the script calling time and the time of 23:59 on a same day${minutesFromNow}`)
              response.scheduleJob = scriptProxy.scheduleRunScriptMinutes(scriptName, data, minutesFromNow)
          
              // the code for your script 
          
              return response
          }
          
          function getMinutesDifference(targetHour, targetMinute) {
              const now = new Date()
              const targetTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), targetHour, targetMinute)
              const differenceInMilliseconds = targetTime - now
              bridge.logInfo(`differenceInMilliseconds between the script calling time and the target time: ${differenceInMilliseconds}`)
              const differenceInMinutes = Math.floor(differenceInMilliseconds / (1000 * 60))
              return differenceInMinutes
          }
          
          main()
          

          The parameters for this script will be 1440 minutes,

          {
            "scriptName": "thisScriptNameItself",
            "args": {
              "interval": 1440
            }
          }
          
          L Offline
          L Offline
          LEE JONG GUN
          wrote on last edited by LEE JONG GUN
          #4

          @JasonL This is what I'm already doing, which is why I'm requesting a new feature, as it has the drawbacks listed above.

          Looking at it again, I see you added time correction. I'll try it.

          1 Reply Last reply
          1

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Solved
          • Unsolved
          • Users