Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to define a Timer with JSON #373

Open
RedAtman opened this issue Mar 29, 2021 · 0 comments
Open

How to define a Timer with JSON #373

RedAtman opened this issue Mar 29, 2021 · 0 comments

Comments

@RedAtman
Copy link

RedAtman commented Mar 29, 2021

Thank you very much for sharing this module.

I tried to define a timer using JSON, and there is an example in the reference document( https://github.com/jruizgit/rules/blob/master/docs/json/reference.md#timers ), but received an error message at runtime.

Error:

Traceback (most recent call last):
  File "/Users/nut/ruler/durable_rules/testpy/Dynamic JSON object rules documentation.py", line 65, in <module>
    host.set_rulesets(rulesets)
  File "/Users/nut/.pyenv/versions/durable_rules/lib/python3.6/site-packages/durable/engine.py", line 778, in set_rulesets
    self.register_rulesets(ruleset_definitions)
  File "/Users/nut/.pyenv/versions/durable_rules/lib/python3.6/site-packages/durable/engine.py", line 887, in register_rulesets
    rulesets = Ruleset.create_rulesets(self, ruleset_definitions)
  File "/Users/nut/.pyenv/versions/durable_rules/lib/python3.6/site-packages/durable/engine.py", line 444, in create_rulesets
    branches[name] = Ruleset(name, host, definition)
  File "/Users/nut/.pyenv/versions/durable_rules/lib/python3.6/site-packages/durable/engine.py", line 317, in __init__
    self._actions[rule_name] = Promise(host.get_action(action))
  File "/Users/nut/.pyenv/versions/durable_rules/lib/python3.6/site-packages/durable/engine.py", line 761, in get_action
    raise Exception('Action with name {0} not found'.format(action_name))
Exception: Action with name restartTimer not found

Example:

from durable.lang import *

rulesets = {
    "timer": {
        "r_0": {
            "any": [
               {
                   "m_0$all": [
                       {
                           "m_0.m": {
                               "$and": [
                                   {
                                       "count": 0
                                   },
                                   {
                                       "$s": 1
                                   }
                               ]
                           }
                       }
                   ]
               },
                {
                   "m_1$all": [
                       {
                           "m_1.m_0": {
                               "$and": [
                                   {
                                       "$lt": {
                                           "count": 5
                                       }
                                   },
                                   {
                                       "$s": 1
                                   }
                               ]
                           }
                       },
                       {
                           "m_1.m_1": {
                               "$t": "MyTimer"
                           }
                       }
                   ]
               }
            ],
            "run": "restartTimer"
        },
        "r_1": {
            "all": [
                {
                    "m": {
                        "cancel": True
                    }
                }
            ],
            "run": "cancelTimer"
        }
    }
}


host = get_host()

host.set_rulesets(rulesets)


post('timer', {'t': 'deposit', 'count': 0, "$s": 1});
post('timer', {'t': 'withrawal', 'count': 1, "$s": 1});
post('timer', {'t': 'chargeback', 'count': 1});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant