Backendless Support
 

Custom business logic - timers

There are two types of custom business logic scrips supported by Backendless - API event handlers and timers.This topic covers the latter. 

A timer is a server-side program deployed to the Backendless server infrastructure which is scheduled to run on a pre-defined schedule. Once the code is deployed, Backendless makes sure the code runs exactly accordingly to the schedule. 

Backendless handles all the runtime aspects - finding an available host to run the code, loading all the dependencies, making sure the code runs securely within an isolated sandbox. Backendless supports a variety of schedules. A timer may be scheduled to run only once, or once a day at the specified time, every day, a few times a week, a month, a year, etc. 

Additionally, a timer may have an expiration date/time. A timer code must be in Java, and we're working on adding support for other server-side languages. The code may use Backendless SDK for Java/Android to interact with the application's data. The example below is a basic timer. All configuration properties of a timer must be specified in the @BackendlessTimer annotation. The annotation accepts a JSON object (as a string) with all the timer properties. For example, the timer below is configured to start on the date/time defined in the startDate property of the annotation. The frequency property sets the timer schedule. 

The code below requests the timer to run every two days.

package com.backendless.myapp.timers;
import com.backendless.servercode.annotation.BackendlessTimer;
@BackendlessTimer("{'startDate':1430195040000,'frequency':{'schedule':'daily','repeat':{'every':2}},'timername':'Cool'}")
public class CoolTimer extends com.backendless.servercode.extension.TimerExtender
{
 @Override
 public void execute( String appVersionId ) throws Exception
 {
 // add your code here
 } 
}

There is a lot more to just creating Timer code. There is a process for testing the timer and  deploying to the Backendless servers. These features will be reviewed in the corresponded Backendless Knowledge Base Topics.

Is article helpful?