简体   繁体   English

什么是最准确的方法来检查您是否在铁路服务器进程中满足Hyperstack的需求

[英]What is the most accurate way to check if you are in rails server process for the needs of Hyperstack

Hyperstack is an isomorphic framework where same code can run server or client side. Hyperstack是一个同构框架,其中相同的代码可以运行服务器或客户端。 So there are specific cases where depending on where some piece of code gets executed (server or client side) different things should be accomplished (client synchronization etc.). 因此,在某些特定情况下,根据某些代码执行的位置(服务器或客户端),应该完成不同的事情(客户端同步等)。

The problem is that relying on the default check if 问题是依赖于默认检查是否

defined?(Rails::Server) 

depends on the webserver you are running and the enclosing environment. 取决于您正在运行的Web服务器和封闭环境。

For example i run on puma (in docker for development and in Ubuntu server for production) and even in that case defined?(Rails::Server) works fine in development but not in production. 例如,我运行puma(用于开发的docker和用于生产的Ubuntu服务器),甚至在那种情况下定义?(Rails :: Server)在开发中工作正常,但在生产中没有。 This reveals that server execution detection depends not only on the actual server you are running on, but also on the method used to start it (ex rails s VS puma start) 这表明服务器执行检测不仅取决于您运行的实际服务器,还取决于用于启动它的方法(ex rails s VS puma start)

Additional information can be found here: 其他信息可以在这里找到:

  1. Detect if application was started as HTTP server or not (rake task, rconsole etc) 检测应用程序是否作为HTTP服务器启动(rake task,rconsole等)

  2. https://gitter.im/ruby-hyperloop/chat?at=59d60f2201110b72317cd61c https://gitter.im/ruby-hyperloop/chat?at=59d60f2201110b72317cd61c

  3. https://hyperstack-org.slack.com/archives/CHRQ5U8HL/p1557262851049900 https://hyperstack-org.slack.com/archives/CHRQ5U8HL/p1557262851049900

Is there a standard way to check whether something in Rails is executing on the server process/thread (not in browser, some sort of client, console, migration, rake task etc.) without relying on some hack to identify or declare what server we deploy on (puma, thin, nginx etc.)? 有没有一种标准的方法来检查Rails中的某些东西是否正在服务器进程/线程上执行(不是在浏览器中,某种类型的客户端,控制台,迁移,rake任务等)而不依赖于某些hack来识别或声明我们的服务器部署(puma,thin,nginx等)?

You can use the RUBY_ENGINE guard to see if the code is running in Opal or not. 您可以使用RUBY_ENGINE防护来查看代码是否在Opal中运行。

if RUBY_ENGINE == 'opal'
    # I am on the client
end

This is very useful in your Isomorphic models to exclude parts of the model's methods from existing on the client. 这在您的同构模型中非常有用,可以从客户端上的现有模型中排除部分模型的方法。 Also very useful for using added Gem methods which make no sense in the client code. 对于使用在客户端代码中没有意义的添加的Gem方法也非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails:最有效的会话存储方式是什么? - rails: what is the most efficient way to store sessions? 在rails 3中进行身份验证的最常用方法是什么? - What is the most common way to do authentication in rails 3? 在Rails 5中运行后台进程的最佳方法是什么? - What is the best way to run a background process in Rails 5? Rails:检查数据库中是否已存在新记录的最有效方法 - Rails: Most efficient way to check if a new record already exists in DB 用Ruby on Rails重新生成静态缓存的最佳方法是什么? - What's the most optimal way to regenerate static cache with Ruby on Rails? 在Rails 3中查询belongs_to关联中的列的最有效方法是什么? - What is the most efficient way to query on columns in belongs_to association in Rails 3? 如何在 Hyperstack 中使用 FontAwsome Icons? - How do you use FontAwsome Icons in Hyperstack? 在生产服务器中进行更新之前,检查子目录rails生产应用程序正确工作的最佳方法是什么? - What is the best way to check the correct work of subdirectory rails production application before update in the production server? Rails:检查整数空的最佳方法是什么? - Rails: What the best way to check empty of integer? Rails-建立多个标签查询的最有效方法是什么 - Rails - what is the most efficient way to build query for multiple tags
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM