Name

global.ProcessEventsJobs

Description

No description available

Script

var ProcessEventsJobs = Class.create();
ProcessEventsJobs.prototype = {
  initialize: function() {
  },
  
  createNewJobs: function(count, enableMultiNode, duration){
  var NAME_PREFIX = 'Event Management - process events';
  var SYSTEM = 'ACTIVE NODES';
  var message;
  if (!duration || duration === '' || isNaN(duration) || duration <= 0 || duration > 24*3600) {
  	duration = 5000;
  	message = gs.getMessage("Event processing jobs are created. Duration: 5 sec");
  	gs.log(message);
  }
  else {
  	duration = duration * 1000; 
  	message = gs.getMessage("Event processing jobs are created. Duration is taken from the property 'Delay (seconds) before processing events that arrive to the DB': {0} sec", duration/1000);
  	gs.log(message);	
  }
  
  /*****************************************************
   *  This value should be in sync with
   *  the calculated field (bucket) on em_event table. 
   *****************************************************/	
  var BUCKET_COUNT = gs.getProperty('evt_mgmt.bucket_count', 100);
  
  
  //delete old ones
  var old = new GlideRecord('sys_trigger');
  old.addQuery('name', 'STARTSWITH', NAME_PREFIX);
  old.query();
  old.deleteMultiple();
  
  
  //create new
  var bucketsPerJob = Math.ceil(BUCKET_COUNT / count);
  var lower = 0;
  var upper =  bucketsPerJob;
  for (var i = 1; i <= count; i++){
  	var jobs = new GlideRecord('sys_trigger');
  	jobs.initialize();
  	if  (count == 1) {
  		jobs.name = NAME_PREFIX ;
  	}
  	else {
  		jobs.name = NAME_PREFIX + ' - ' + i;
  	}
  	if (enableMultiNode == 'true') //should support multi node - specify System as ACTIVE NODES
  		jobs.system_id = SYSTEM;
  	jobs.priority = 50;
  	jobs.trigger_type = 1; //REPEAT
  	jobs.state = 0; 	   //READY
  	var duration = new GlideDuration(duration);
  	jobs.repeat = duration;
  	jobs.upgrade_safe = true;
  	
  	jobs.script = 'var eventProcessor = new SNC.EvtMgmtEventProcessor(); eventProcessor.processWithLimit('+ lower + ',' + upper+ ');';
  	
  	jobs.insert();
  	lower = lower + bucketsPerJob;
  	upper = upper + bucketsPerJob;
  }
},

  type: 'ProcessEventsJobs'
};

ProcessEventsJobs.get = function() {
  return new ProcessEventsJobs();
};

Sys ID

f4ed16f093c43300a0c231f6357ffb7b

Offical Documentation

Official Docs: