How can I invalidate sources asynchronously

#1

I have successfully tested my analytic using AnalyticsContainer.invalidateSources. Unfortunately that function is synchronous. How can I invalidate the same period of time across many sources, and take advantage of parallel processing in the cluster?

0 Likes

#2

I’ve used a MapReduce job to accomplish this. To minimize provisioning, I create a JSMapReduce job which allows my to create MapReduce jobs on the fly.

The mapFunction iterates through a list of IDs, firing one or more analytics for each ID for a given evaluation period

 var mapFunction = function map(batch, objs, job) { 
	var log = C3.logger("mylogger");
	var ids = objs.pluck('id');  
	var tag = Tag.get("prod");
	var typeId = Tag.getTypeId('-', 'TypeName');
	var start = "2016-01-01";
	var end = "2017-07-01"; 

	ids.forEach(function (id) {
		try {
			AnalyticsContainer.fireAnalytics(
				[
					{
						typeId:  Tag.getTypeId('-', 'TypeName'),
						objId: id,
						timeRanges: [{start: start, end: end}]
					}
				],
				["Analytic1", "Analytic2"],
				{forceReEval: true}
			);
		} catch (e) {
			log.error("Error calling fireAnalytics -- " + id + "   --- " + e);
		}

	})
	
}

You can then create a JSMapReduceSpec, passing the mapFunction as the map function and specifying additional MapReduce evaluation parameters.

 var spec = JSMapReduceSpec.make({
	  targetType : {typeName:"TelemetryAsset", moduleName:"-"},
	  include: "id",
	  limit: -1, 
	  batchSize: 50,
	  filter:  "hasSomething == true"
	  map : mapFunction,
	});

Lastly, invoke the job.

 var job = JS.mapReduce(spec);
0 Likes