在 Erlang 和 Rails(以及 mongodb)之间共享模型定义
我有一个通过 mongomapper 使用 mongodb 的 Rails 应用程序,一切都很好。问题是...我想要使用 erlang 进行一些后台处理,并且我想使用此处理的结果更新相同的 mongo/mongomapper 模型。在两个应用程序(rails 和 erlang)之间共享模型定义并保持理智的最佳方式是什么?如果它们都访问相同的记录,那么尝试单独管理它们似乎会出现问题。如果没有“好”方法,我是否只是以错误的方式处理这个问题?
附加信息:我最初是使用 starling/workling 客户端进行后台处理。这很好,因为我可以使用所有相同的 Rails 模型和代码。但性能很糟糕,所以我希望 erlang 能够解决一些效率问题。正在处理大量数据,但可以轻松并行处理。
我试图避免通过rest或thrift接口使用erlang作为mongodb和rails之间的唯一中介。
编辑:我想对此进行更多的阐述。 Erlang 处理需要事先了解一些模型。我基本上使用 erlang 从其他地方提取数据并填充模型对象的详细信息。例如,我可能使用 xmerl_xpath:string("//description/text()") 从 xml 文件中抓取一个描述字段。我需要能够添加这样的方法来作用于模型的字段。
I have a rails app using mongodb through mongomapper and all is well. The problem is... I'm going to want to use erlang to do some background processing and I want to update the same mongo/mongomapper models with the results of this processing. What's the best way to share model definitions between the two apps (rails and erlang) and remain sane? Seems like it would be problematic to try to manage them separately if they're both accessing the same records. If there's no "good" way, am I simply approaching this the wrong way?
Additional info: I was originally doing the background processing using starling/workling clients. This is nice since I could use all of the same rails models and code. Performance was terrible though so I'm looking to erlang to solve some of the efficiency problems. It's a large amount of data being processed, but it can be easily processed in parallel.
I'm trying to avoid using erlang as the sole mediator between mongodb and rails through a rest or thrift interface.
Edit: I wanted to shine a little more light on this. The erlang processing will need to know a little bit about the models beforehand. I'm basically using erlang to pull data from other places and fill in details of the model objects. So, for example, there may be a description field that I'm scraping from an xml file using xmerl_xpath:string("//description/text()"). I need to be able to add methods like this that will act upon fields of the model.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MongoDB 有两个社区支持的 Erlang 驱动程序(erlmongo 和 emongo)。通过这些驱动程序访问 mongodb 将为您提供本机 Erlang 对象。
红宝石-> MongoMapper-> Mongo ruby 驱动程序 -> MongoDB-> (emongo | erlmongo)->埃尔兰
MongoDB has two community-supported Erlang drivers (erlmongo and emongo). Accessing your mongodb through those drivers will give you native Erlang objects.
Ruby -> MongoMapper -> Mongo ruby driver -> MongoDB -> (emongo | erlmongo) -> Erlang