gorules / zen

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

Calling zen.evaluate inside a function fails #238

Open bjorntheart opened 2 weeks ago

bjorntheart commented 2 weeks 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 weeks 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 weeks 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 weeks 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 weeks 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 };
    }),
  );