jruizgit / rules

Durable Rules Engine
MIT License
1.16k stars 206 forks source link

Redis, rule updates and temporal relations? #319

Open MStumpp opened 4 years ago

MStumpp commented 4 years ago

I have a few questions I did not find answers for:

1.) How to use a Redis store? In particular, how to configure durable to use Redis? 2.) Is it possible to update the rule set during execution time? 3.) How to model temporal relations of events? E.g. consequent should fire only if event A: { 'type' : 'TypeA' } was occurring n seconds before: event B: { 'type' : 'TypeB' } I found this issue https://github.com/jruizgit/rules/issues/168 but its referring to some other scenario.

jruizgit commented 4 years ago

Hi, thanks for asking the questions.

  1. State offloading to Redis can be implemented as an extension. Please follow the example (also available for Python): https://github.com/jruizgit/rules/blob/master/testjs/testdurable.js
  2. No it is not possible
  3. You can set a timestamp in your events, you can also use a timer: https://github.com/jruizgit/rules/blob/master/docs/js/reference.md#timers
MStumpp commented 4 years ago

Thanks for the quick response.

If 1.) works, wouldn't it be possible to just reuse the state stored Redis?

provideDurability(d.getHost());

let's say i run this first:

d.ruleset('test', function() {
    whenAll: {
        m.subject == 'Hello'
    }
    run: {
        console.log('fired test');
    }
});

then restart the program with the following update:

d.ruleset('test', function() {
    whenAll: {
        m.subject == 'World'
    }
    run: {
        console.log('fired world');
    }
});

(or even add another ruleset 'test_2' and attaching it to d)

jruizgit commented 4 years ago

Yes, you should be able to do that as long as the new ruleset is compatible with the data model of the old one.

nixphix commented 4 years ago

@jruizgit I'm looking for Redis store for python, I did check testdynamic.py it seems to be outdated for the current version.

The Host class doesn't have a public run function anymore. Also the get_host() uses a global var for host. In comparison to the js implementation you have mentioned above python extension seems incomplete.

Could you please give me some pointers on offloading the data store to Redis, cause our application is distributed across various worker nodes.

zellelin commented 3 years ago

@jruizgit I'm looking for Redis store for python, I did check testdynamic.py it seems to be outdated for the current version.

The Host class doesn't have a public run function anymore. Also the get_host() uses a global var for host. In comparison to the js implementation you have mentioned above python extension seems incomplete.

Could you please give me some pointers on offloading the data store to Redis, cause our application is distributed across various worker nodes. @nixphix hi,could you solve this question.i have the same situation with python.