两个Rails应用之间的共享模型-什么是Workflow的理想解决方案? [英] Shared models between two Rails apps - what is the ideal solution for Workflow?

查看:90
本文介绍了两个Rails应用之间的共享模型-什么是Workflow的理想解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事一个Rails 3项目,该项目分为四个部分:

I am currently working on a Rails 3 project that is divided up into four parts:

  • 面向公众的网站
  • 管理网站/后端
  • 模型
  • 用于第三方数据访问的API

由于模型是在三个关键组件之间共享的,因此我希望避免它们被包含在一个主项目中,但是每个部分都需要访问模型,但是我不想重复代码并且到处都有不同的版本

As the models are shared between the three key components I want to keep them away from being in one main project, however each part needs access to the models, but I don't want to repeat the code and have different versions everywhere.

当前,我将模型代码保存在gem中,并且在每个项目的Gemfile中,我用以下行引用它们:

Currently I have the model code in a gem, and in each project's Gemfile I am referencing them with the following line:

gem "my_models", :path => "../my_models/"

但是,当我部署到测试服务器以供同事评估系统时,我需要从外部存储库中提取模型,因此我将上面的代码替换为以下内容:

However when I deploy to our test servers for my co-workers to evaluate the system on I need to pull the models from an external repository, so I swap out the above line with the following:

gem "my_models", :git => "git@private.repository.com:username/my_models.git"

这本身可以很好地工作,但是就版本"而言它相当笨拙(即,每次我希望将所做的更改部署到测试服务器时,我都需要更改版本),将其切换为使用git来代替本地,并确保我正确地推送了文件.

This in its self works well, but its quite clunky in terms of 'versions' (i.e. I need to bump the version every time I wish to deploy the changes to the test servers), switch the line over to use git instead of local, and make sure that I'm pushing the files properly.

以前我使用的是共享的git子模块,但这很尴尬.

Previously I was using a shared git submodule, but this was just as awkward.

我宁愿不要将所有内容都构建到一个大型项目中,因为这些项目会变得异常庞大且难以维护,并且如果可能的话,我也想将关注点分开,因此我对管理站点所做的任何更改都不会有很多机会影响其他组件-显然,模型可能会引起问题,但这是我已经考虑并理解的风险.

I would rather not build everything into one mega-project, as these tend to become monstrous and difficult to maintain, and I would also like to separate concerns if possible, so any changes I make to the administration site doesn't have much of a chance to impact the other components - obviously the models have the potential to cause issues, but that is a risk I have considered and understand.

当涉及到这样的事情时,外面的人会提出什么建议?或者,我是完全按照错误的方式进行操作的吗?

What would people out there suggest when it comes to something like this? Or, am I going about it completely the wrong way?

一些其他背景:

此应用是对现有网站的重写,该网站遵循将所有内容整合到一个项目中"的模式-不幸的是,这里有两个问题:

This app is a rewrite of an existing website which followed the model of 'lump everything into the one project' - unfortunately there are two issues here:

  1. 该应用程序的开发很差-我继承了这个项目,当我初次使用它时,单个用户的加载时间约为每页2分钟-此后虽然有所减少,但仍然存在问题
  2. 我们目前处于当前站点的容量极限,并且我们预计在接下来的6个月中将需要承担更多的负载-但是使用多合一"应用程序进行扩展意味着我们将浪费资源扩展不需要的网站后端.

本质上,我想分开两件事-前端(是公共网站和API)和后端-我所了解的有关软件开发的一切都告诉我,将所有这些结合在一起并不是一个理想的解决方案(并且过去的历史向我表明,将这两部分分开是确保前端性能的好举动.

Essentially there are two things I want to separate - the Front end (being the public website and the API) and the back end - everything I know about software development tells me that combining all this together is not an ideal solution (and past history shows me that splitting these two is a good move in terms of ensuring front end performance).

也许我需要从另一个角度看待这个问题-将模型保留在每个项目中,而不是在项目之间共享模型,而要为每个功能区域分配一个缩减的功能子集(即后端需要知道谁创建了一个发布,但前端并不真正在乎,因此在读取模型时忽略该逻辑).

Perhaps I need to look at this from another angle - keep the models in each project, and instead of sharing them between projects have a cut-down subset of functionality for each functional area (i.e. the backend needs to know who created a post, but the front end doesn't really care about that, so omit that logic when reading in the model).

推荐答案

拖放模型项目(将模型放入其他部分之一,我建议无论您认为更重要的部分"),将所有项目放入单个存储库中(单独的项目文件夹),并建立到模型/libs/apis/任何内容的符号链接

drop the models project(put models into one of other parts, i'd suggest whatever you consider "more important"), put all projects into single repository(separate project folders) and make symlinks to models/libs/apis/whatever

您的代码高度耦合在一起,您经常需要一次对几个项目进行更改(例如更新模型更新使用它们的API等)

your code is highly coupled together and you often need to make changes to few projects at once(like updating models and updating APIs that use them, etc)

关于单存储库符号链接设置的一件好事是,您的提交将减少碎片,并且通常代表完整的功能实现-易于跟踪错误,读取历史记录和维护代码库

one nice thing about single-repo-symlink setup is that your commits will be less fragmented and will usually represent full feature implementation - easier to track bugs, read history and maintain codebase

同样,在部署时,您无需从许多存储库中进行读取-那里的故障点减少了

also when you deploy you don't need to read from many repositories - one less point of failure right there

使用模型这样的发布过程也更加简单,因为分支现在可以容纳所有项目的范围

release process is also simpler with such model as branch will now hold the scope of all projects

有一些缺点,例如符号链接在Windows上无法正常工作,对我而言却完美

there are some drawbacks like symlinks dont work that well on windows and whatnot but for me it works perfectly

这篇关于两个Rails应用之间的共享模型-什么是Workflow的理想解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆