Esempio n. 1
0
 def default(self, obj):
     if isinstance(obj, DeploymentSchema):
         return {
             DAGNODE_TYPE_KEY: "DeploymentSchema",
             "schema": obj.dict(),
         }
     elif isinstance(obj, RayServeHandle):
         return serve_handle_to_json_dict(obj)
     elif isinstance(obj, RayServeDAGHandle):
         # TODO(simon) Do a proper encoder
         return {
             DAGNODE_TYPE_KEY: RayServeDAGHandle.__name__,
             "dag_node_json": obj.dag_node_json,
         }
     elif isinstance(obj, RayServeLazySyncHandle):
         return {
             DAGNODE_TYPE_KEY: RayServeLazySyncHandle.__name__,
             "deployment_name": obj.deployment_name,
             "handle_options_method_name": obj.handle_options.method_name,
         }
     # For all other DAGNode types.
     elif isinstance(obj, DAGNode):
         return obj.to_json(DAGNodeEncoder)
     else:
         # Let the base class default method raise the TypeError
         try:
             return json.JSONEncoder.default(self, obj)
         except Exception as e:
             raise TypeError(
                 "All args and kwargs used in Ray DAG building for serve "
                 "deployment need to be JSON serializable. Please JSON "
                 "serialize your args to make your ray application "
                 "deployment ready."
                 f"\n Original exception message: {e}")
Esempio n. 2
0
 def default(self, obj):
     if isinstance(obj, DeploymentSchema):
         return {
             DAGNODE_TYPE_KEY: "DeploymentSchema",
             "schema": obj.dict(),
         }
     elif isinstance(obj, RayServeHandle):
         return serve_handle_to_json_dict(obj)
     elif isinstance(obj, RayServeDAGHandle):
         # TODO(simon) Do a proper encoder
         return {
             DAGNODE_TYPE_KEY: RayServeDAGHandle.__name__,
             "dag_node_json": obj.dag_node_json,
         }
     elif isinstance(obj, RayServeLazySyncHandle):
         return {
             DAGNODE_TYPE_KEY: RayServeLazySyncHandle.__name__,
             "deployment_name": obj.deployment_name,
             "handle_options_method_name": obj.handle_options.method_name,
         }
     # For all other DAGNode types.
     elif isinstance(obj, DAGNode):
         return obj.to_json(DAGNodeEncoder)
     else:
         return json.JSONEncoder.default(self, obj)
Esempio n. 3
0
    async def test_basic(self, serve_instance, sync):
        handle = get_handle(sync)
        assert await call(handle, "hi") == "hi"

        serialized = json.dumps(serve_handle_to_json_dict(handle))
        # Check we can go through multiple rounds of serde.
        serialized = json.dumps(json.loads(serialized))

        # Load the handle back from the dict.
        handle = serve_handle_from_json_dict(json.loads(serialized))
        assert await call(handle, "hi") == "hi"