【问题标题】:`rails server` hangs when there are multiple requests at the same time当同时有多个请求时,`rails server` 挂起
【发布时间】:2017-04-28 06:19:12
【问题描述】:

我有一个 angular2 应用程序。在导航到route 之前,我正在使用resolve 获取一些数据。

我在路线上这样做:

resolve: {
        businessRules: NewEventResolverService,
        countries: NewEventCountriesResolverService,
        locations: NewEventLocationsResolverService
}

这些服务中的每一个都向我的 Rails API 服务器(Rails 5)发送一个 GET 请求。 因此,当我导航到上述路线时,rails 服务器会挂起并且没有返回任何数据。

然后我把它改成了只有一个解析器服务:

resolve: {
        allPrerequisites: NewEventResolverService
}

在解析器服务中,一个接一个地发送GET请求。

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<any> {
    return this.service.getActiveBusinessRule().then((lookupRecords: LookupKeyValuePair[]) => {
        return this.service.getActiveCountries().then((countries: Country[]) => {
            return this.service.getActiveLocationsOfClient().then((locations: Location[]) => {
                return {
                        lookupRecords: lookupRecords,
                        countries: countries,
                        locations: locations
                }
            })
        })
    })
}

这次服务器没有挂起。我如何使它与 Rails 服务器的多个并发请求一起工作?

【问题讨论】:

  • 能否请您详细说明一下如何使其与 Rails 服务器的多个并发请求一起工作?
  • 使第一个案例工作 - 同时发送所有三个请求到服务器。

标签: ruby-on-rails angular


【解决方案1】:

在 Rails 5 中

在 application.rb 中创建 config.allow_concurrency=true

【讨论】:

    猜你喜欢
    • 2018-09-29
    • 2011-02-19
    • 2019-06-24
    • 2011-11-28
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    相关资源
    最近更新 更多