node-rules icon indicating copy to clipboard operation
node-rules copied to clipboard

Question: Running facts in batches

Open phzietsman opened this issue 9 years ago • 3 comments

Firstly thanks a lot for this library! Working with this has been a pleasure!

I wrapped your library in a REST API. I then sent it batches of anything from 100 to a 1000 records / facts to evaluate. The API call must only resolve once all the facts have been evaluated. I achieved it using Q like below.

function run(facts) {

	var promises = [];

	facts.forEach(function(value, key) {
		promises.push(perFactRuleRunner(value));
	});

	return Q.all(promises);
}

function perFactRuleRunner(fact) {

	var defer = Q.defer();

	R.execute(fact, function(data) {
		defer.resolve(data);
	}, function(error){
		defer.reject(error);
	});

	return defer.promise;
}

Is there a builtin way to achieve the same result, or must I stick with this?

phzietsman avatar Jan 06 '17 08:01 phzietsman

This is not supported in the current version - 4.0.0.

nikollatesla avatar May 15 '18 12:05 nikollatesla

@phzietsman Can you please tell me how can I get the response data using this code for a bunch of facts?

sabeelahmad avatar Jul 19 '20 14:07 sabeelahmad

@phzietsman Can you please tell me how can I get the response data using this code for a bunch of facts?

This has been a while.

I'd swap out Q for native Javascript promises and look at promise all (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)

phzietsman avatar Jul 20 '20 16:07 phzietsman

Hey thanks for the feedback. Please consider raising a PR incase you have any directions on improving the existing flow control apis. Closing since there is no open items that can be picked up as a bug or feature addition.

mithunsatheesh avatar Mar 05 '23 10:03 mithunsatheesh