0

Posting Json for durable rules does not allow to format date.

Posting string into variable works.

from datetime import datetime

a="11-02-2020"
start = datetime.strptime(a, "%d-%m-%Y")
end = datetime.strptime("11-02-2020", "%d-%m-%Y")
a= start > end
print(start)

Example code that is not working :

from durable.lang import *

import json
from datetime import datetime

with ruleset('test'):
    def method(c):
        a=str(m.InsertDate)
        start = datetime.strptime(a, "%d-%m-%Y")
        end = datetime.strptime("11-02-2020", "%d-%m-%Y")
        b= start > end
        print(start, b)
post('test', {'InsertDate':'02-03-2020'})

Error received: raise MessageNotHandledException(message)

durable.engine.MessageNotHandledException: {'InsertDate': '02-03-2020'}

Kix
  • 1

3 Answers3

0

Use time.time() instead of dates

nagyl
  • 1,644
  • 1
  • 7
  • 18
  • Thank you for the feedback. Unfortunately, it does not solve my problem. time.time() would give me clock info. The json input is not recognized. My end goal would be to compared two dates. Something like this @when_all ((m.InsertDate >= StartDate) & (m.InsertDate <= EndDate)). – Kix Mar 04 '20 at 16:02
0

I believe from my investigation it is the framework of durable-rules that is unable to load json data and perform further actions. Got the same error when tried to sum to integer from json.

Kix
  • 1
0

from durable.lang import *
from datetime import datetime

with ruleset('test1'):
    @when_all(+m.insertDate)
    def compare_date(c):
        a=str(c.m.insertDate)
        start = datetime.strptime(a, "%d-%m-%Y")
        end = datetime.strptime("11-02-2020", "%d-%m-%Y")
        b= start > end
        print(start, b)
post('test1', {'insertDate':'02-03-2020'})

tony
  • 81
  • 1
  • 2