gorules / zen

Open-source Business Rules Engine for your Rust, NodeJS, Python or Go applications.
https://gorules.io
MIT License
835 stars 80 forks source link

Calling zen.evaluate inside a function fails #238

Closed bjorntheart closed 1 month ago

bjorntheart commented 2 months ago

I'm on a free trial of cloud on gorules.io

I have a function that calls zen.evaluate() on another decision that is published and get the following error Screenshot 2024-09-05 at 08 59 38

bjorntheart commented 2 months ago

Turns out you can't have a spaces in the folder name otherwise under the hood the decision loader fails. I'd suggest that there be some validation on naming rules for decision documents and folder naming.

Feel free to close.

bjorntheart commented 2 months ago

Also, running await zend.evaluate() in

.map(async function(o) {
  // params left out for brevity
  await zen.evaluate(...)
})

doesn't work.

What works is running it inside a regular for loop like so:

for (const [k, bike] of Object.entries(bikes)) {
  let result = await zen.evaluate('ererer/insurables/bike.json', bike, { trace: true });
  console.log({ result });    
}
ivanmiletic commented 2 months ago

Hi Bjorn, we will take a look at it why it isn't working in map. Can you try:

await Promise.all(somelist.map(async () => { return await zen.evaluate(); }));

bjorntheart commented 2 months ago

Works like a charm, thanks @ivanmiletic. Right after you commented I remembered I had some code lying around doing just that.

  let evaluated = await Promise.all(
    bikes.map(async function (insurable) {
      let r = await decision.evaluate(insurable, { trace: false });
      return { ...r.result, insurable };
    }),
  );
stefan-gorules commented 1 month ago

Closing as the thread has been resolved.