Skip to content

hopeful to add support for orjson to speed up event json passing #407

@sonicgemini

Description

@sonicgemini

otherwise need to add monkey patch, like (copy from google advice and tested it worked)

# in engine.py file
import orjson  # add this
import json
import copy
import durable_rules_engine

from . import logger

# 1. Define a wrapper because orjson returns bytes, but durable-rules needs strings
def orjson_dumps_wrapper(obj, **kwargs):
    # Durable-rules may pass arguments like 'ensure_ascii' which orjson doesn't use
    return orjson.dumps(obj).decode('utf-8')

def orjson_loads_wrapper(s, **kwargs):
    return orjson.loads(s)

# 2. Monkey-patch the standard json module used by durable-rules
# This must be done BEFORE importing or using durable-rules functions
json.dumps = orjson_dumps_wrapper
json.loads = orjson_loads_wrapper

def _unix_now():
    dt = datetime.datetime.now()
.......

is is possible to add an engine support to couple the json dependency by adding injection setting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions