Skip to content

About Timers

A timer in the Backendless custom business logic system is a block of code with some execution schedule. A timer itself does not need to perform any scheduling work, Backendless automatically calculates the time for the next execution step of the timer, allocates computing resources and runs the code. Consider the following timer implementation:

/**
* CoolTimer timer.
* It is executed according to the schedule
*/
Backendless.ServerCode.addTimer({

  name: 'CoolTimer',

  startDate: 1491929303000,

  frequency: {
    schedule: 'custom',

    repeat: {'every':120}
  },

  /**
  * @param {Object} req
  * @param {String} req.context Application Version Id
  */
  execute(req){
    Backendless.Data.of( "TimerLog" ).save( { timerContext: JSON.stringify(req) })
  }
});

A timer must follow the following guidelines:

  • A timer must define the name, startDate and frequency properties.
  • Code must use the Backendless.ServerCode.addTimer function to register a timer.
  • The frequency property defines the timer execution schedule.
  • The execute( req ) function must contain the business logic of the timer.