Timer not working in production, working in debug

My timer code to search and update a field is working in debug but it’s not working in production. Nothing complicated, just a search and an update.

Code is as follows:
Backendless.ServerCode.addTimer({

name: ‘UpdateCompletedCases’,

startDate: 1471341600000,

frequency: {
schedule: ‘custom’,

repeat: {'every':60}

},

/**

  • @param {Object} req

  • @param {String} req.context Application Version Id
    */
    execute(req){
    //add your code here

    function Cases(args) {
    args = args || {};
    this.EndDate = args.EndDate || “”;
    this.Status = args.Status || “”;
    }

    function casesFound(result) {
    //console.log(“cases found”);

    for (i = 0; i < result.data.length; i++)
    {
    function casesSaved(saveresult) {
    //console.log(“cases saved”);
    }

    var casedata = result.data;
    casedata["Status"] = "Completed";
    caseStorage.save(casedata,  new Backendless.Async(casesSaved, gotError));
    

    }

    }

    function gotError(err) {
    //console.log("error message - " + err.message);
    //console.log("error code - " + err.statusCode);
    }

    function date_and_time() {
    var date = new Date();
    //zero-pad a single zero if needed
    var zp = function (val){
    return (val <= 9 ? ‘0’ + val : ‘’ + val);
    }

    //zero-pad up to two zeroes if needed
    var zp2 = function(val){
    return val <= 99? (val <=9? ‘00’ + val : ‘0’ + val) : (’’ + val ) ;
    }

    var d = date.getDate();
    var m = date.getMonth() + 1;
    var y = date.getFullYear();
    var h = date.getHours();
    var min = date.getMinutes();
    var s = date.getSeconds();
    var ms = date.getMilliseconds();
    return ‘’ + zp(m) + ‘/’ + zp(d) + ‘/’ + y + ’ ’ + zp(h) + ‘:’ + zp(min) + ‘:’ + zp(s);
    }

    var query = “Status = ‘Accepted’ and EndDate < '” + date_and_time() + “’”;

    var caseStorage = Backendless.Persistence.of( Cases );
    var dataQuery = new Backendless.DataQuery();
    dataQuery.condition = query;
    var cases = caseStorage.find( dataQuery , new Backendless.Async(casesFound, gotError));

}
});

Please see this chapter in the doc:

https://backendless.com/documentation/business-logic/js/bl_sync_vs_async_code.htm

Hello Mark,

I enabled promises but still the same issue. the code works in debug perfect but not when deployed.

The logger shows the timmer getting called but does nothing. why does it work in debug and not in production?

Code is as follows:

Backendless.enablePromises();
Backendless.ServerCode.addTimer({

name: ‘UpdateCompletedCases’,

startDate: 1471341600000,

frequency: {
schedule: ‘custom’,

repeat: {'every':60}

},

/**

  • @param {Object} req

  • @param {String} req.context Application Version Id
    */
    execute(req){
    //add your code here

    Backendless.Logging.setLogReportingPolicy( 1, 1 );
    var logger = Backendless.Logging.getLogger( “MyLogger”);
    logger.info( “timer called” );
    //logger.warn( “warning message” );
    //logger.debug( “debug message” );
    //logger.error( “error message” );

    function Cases(args) {
    args = args || {};
    this.EndDate = args.EndDate || “”;
    this.Status = args.Status || “”;
    }

    function casesFound(result) {
    //console.log(“case found”);
    logger.debug( “case found” );

    for (i = 0; i < result.data.length; i++)
    {
    function casesSaved(saveresult) {
    //console.log(“case saved”);
    logger.debug( “case saved” );
    }

    var casedata = result.data;
    casedata["Status"] = "Completed";
    caseStorage.save(casedata,  new Backendless.Async(casesSaved, gotError));
    

    }

    }

    function gotError(err) {
    //console.log("error message - " + err.message);
    //console.log("error code - " + err.statusCode);
    Promise.reject("error message - " + err.message);
    logger.error("error message - " + err.message);
    }

    function date_and_time() {
    var date = new Date();
    //zero-pad a single zero if needed
    var zp = function (val){
    return (val <= 9 ? ‘0’ + val : ‘’ + val);
    }

    //zero-pad up to two zeroes if needed
    var zp2 = function(val){
    return val <= 99? (val <=9? ‘00’ + val : ‘0’ + val) : (’’ + val ) ;
    }

    var d = date.getDate();
    var m = date.getMonth() + 1;
    var y = date.getFullYear();
    var h = date.getHours();
    var min = date.getMinutes();
    var s = date.getSeconds();
    var ms = date.getMilliseconds();
    return ‘’ + zp(m) + ‘/’ + zp(d) + ‘/’ + y + ’ ’ + zp(h) + ‘:’ + zp(min) + ‘:’ + zp(s);
    }

    var query = “Status = ‘Accepted’ and EndDate < '” + date_and_time() + “’”;

    var caseStorage = Backendless.Persistence.of( Cases );
    var dataQuery = new Backendless.DataQuery();
    dataQuery.condition = query;
    var cases = caseStorage.find( dataQuery , new Backendless.Async(casesFound, gotError));

}
});

Enabling promises is not sufficient, the code must return a promise as it is described in the doc and shown in the examples.

Regards,
Mark

Hi @mark-piller
this link is empty,
https://backendless.com/documentation/business-logic/js/bl_sync_vs_async_code.htm
could you Please share the updated link.
as I am also facing timer related issue
The log shows the timmer getting called without error but does nothing.

Hi @Ayaz_Khan ,

here it is:

https://backendless.com/docs/bl-js/bl_troubleshooting.html#servercode-works-well-in-the-debug-mode-but-does-not-when-deployed-to-the-cloud