rules
rules copied to clipboard
AttributeError: 'NoneType' object has no attribute '__call__' [Gunicorn implementation]
I was using you gunicorn implementation but I was unable to make any curl requests, here is your code. I am in dire need of your help please respond.
with ruleset('animal'):
@when_all(c.first << (m.verb == 'eats') & (m.predicate == 'flies'),
(m.verb == 'lives') & (m.predicate == 'water') & (m.subject == c.first.subject))
def frog(c):
c.assert_fact({ 'subject': c.first.subject, 'verb': 'is', 'predicate': 'frog' })
@when_all(c.first << (m.verb == 'eats') & (m.predicate == 'flies'),
(m.verb == 'lives') & (m.predicate == 'land') & (m.subject == c.first.subject))
def chameleon(c):
c.assert_fact({ 'subject': c.first.subject, 'verb': 'is', 'predicate': 'chameleon' })
@when_all((m.verb == 'eats') & (m.predicate == 'worms'))
def bird(c):
c.assert_fact({ 'subject': c.m.subject, 'verb': 'is', 'predicate': 'bird' })
@when_all((m.verb == 'is') & (m.predicate == 'frog'))
def green(c):
c.assert_fact({ 'subject': c.m.subject, 'verb': 'is', 'predicate': 'green' })
@when_all((m.verb == 'is') & (m.predicate == 'chameleon'))
def grey(c):
c.assert_fact({ 'subject': c.m.subject, 'verb': 'is', 'predicate': 'grey' })
@when_all((m.verb == 'is') & (m.predicate == 'bird'))
def black(c):
c.assert_fact({ 'subject': c.m.subject, 'verb': 'is', 'predicate': 'black' })
@when_all(+m.subject)
def output(c):
print ('Fact: {0} {1} {2}'.format(c.m.subject, c.m.verb, c.m.predicate))
# caching the rules_app
rules_app = None
def run_app(host, application):
global rules_app
rules_app = application
# delegating all calls to the rules_app
def app(environ, start_response):
return rules_app.__call__(environ, start_response)
if __name__ == '__main__':
run_server(run_app)
heres the console output
File "gun_server.py", line 42, in app
return rules_app.__call__(environ, start_response)
AttributeError: 'NoneType' object has no attribute '__call__'
Hi, thanks for asking the question. What version are you using? If you are using, durable_rules 2.x, it no longer implements a REST service. This gives you flexibility to decide how to implement your http API. For reference, this is the V1 http API implementation:
https://github.com/jruizgit/rules/blob/v0/libpy/durable/interface.py
Thank you for replying in such a short time what I am looking for is sending a post request where I am sending a = 'x' and b='y' and I need to rule for a='x' and b='y' as a JSON response, but what I am getting is.
{"outcome": {"$s": 1, "sid": "0", "id": "sid-0"}}
How am I supposed to use durable rules for getting the predefined rule for certain dynamic parameters such as a='x' and b='y', it would be nice if you could shine some light on this.
Hi, I'm not sure I understand your scenario. In the case below, the post call will return the context set when the rule is triggered. Is that what you are looking for?
from durable.lang import *
with ruleset('test'):
# antecedent
@when_all(m.subject == 'World')
def say_hello(c):
# consequent
print('test-> Hello {0}'.format(c.m.subject))
c.s.state = 'say_hello'
print(post('test', { 'subject': 'World' }))