Skip to content
Snippets Groups Projects
process.js 1.34 KiB
Newer Older
import("system.logging");
import("Bulkmail_lib");
import("system.project");
import("system.datetime");
import("Sql_lib");
import("KeywordRegistry_basic");
import("system.eMath");
import("system.SQLTYPES");

var dateToSendPassedAfter = project.getInstanceConfigValue("bulkmail.dateToSendPassedAfter" , 24);


//send all Bulkmails which are currently planned and not already missed.
var bulkMailData = newSelect("BULKMAIL.BULKMAILID")
.from("BULKMAIL")
.where("BULKMAIL.STATUS",$KeywordRegistry.bulkMailStatus$planned())
.and("BULKMAIL.DATE_TO_SEND", datetime.date(), SqlBuilder.LESS_OR_EQUAL())
.and("BULKMAIL.DATE_TO_SEND",eMath.subInt(datetime.date(), eMath.mulInt(dateToSendPassedAfter, datetime.ONE_HOUR)), SqlBuilder.GREATER())
.arrayColumn();
logging.log(JSON.stringify(bulkMailData));
for (let i = 0; i < bulkMailData.length; i++){
     newWhere("BULKMAIL.BULKMAILID", bulkMailData[i])
        .updateFields({"STATUS" : $KeywordRegistry.bulkMailStatus$beingSent()});
    
    BulkMailUtils.sendBulkMailOnServer(bulkMailData[i],null,null);
}

//set all missed bulkmails to status missed
newWhere("BULKMAIL.STATUS",$KeywordRegistry.bulkMailStatus$planned())
.and("BULKMAIL.DATE_TO_SEND",eMath.subInt(datetime.date(), eMath.mulInt(dateToSendPassedAfter, datetime.ONE_HOUR)), SqlBuilder.LESS_OR_EQUAL())
.updateFields({"STATUS" : $KeywordRegistry.bulkMailStatus$missed()});