【问题标题】:Heroku Error: ArgumentError: invalid uri scheme ''Heroku 错误:ArgumentError:无效的 uri 方案''
【发布时间】:2016-12-09 19:12:01
【问题描述】:

我正在尝试让我的 Rails 应用程序使用 Sidekiq 处理后台作业,并将 Sidekiq 与 Heroku 上的 redis-to-go 连接起来。这是我的Procfile

web: bundle exec puma -C config/puma.rb
worker: bundle exec -C config/sidekiq.yml

这是我的 Sidekiq.rb 初始化文件:

require 'sidekiq'

Sidekiq.configure_client do |config|  
  config.redis = { url: ENV['REDIS_PROVIDER'] }
end 

Sidekiq.configure_client do |config|  
   config.redis = { url: ENV['REDIS_PROVIDER'] }
end

REDIS_PROVIDER 变量在 Heroku 中设置为 REDISTOGO_URL。根据here 提供的说明,我还添加了一个初始化文件redis.rb。以下是内容:

uri = URI.parse(ENV["REDIS_PROVIDER"])
REDIS = Redis.new(:url => uri)

我收到以下错误,不知道如何解决。 Heroku 也抛出了 H10 错误

[3] ! Unable to load application: ArgumentError: invalid uri scheme '

/app/vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:416:in `_parse_options': invalid uri scheme '' (ArgumentError) 

更新:

我在 Heroku 上回滚到以前的版本并从 gemfile 中删除了 redis gem,删除了 redis 初始化文件,应用程序不再崩溃。但是后台作业仍然无法正常工作,并且我在日志中收到这些错误:

heroku/worker.1:  Starting process with command `bundle exec -C config/sidekiq.yml`
heroku/worker.1:  State changed from starting to up
app/worker.1:  bundler: command not found: -C 
heroku/worker.1:  Process exited with status 127 
heroku/worker.1:  State changed from up to crashed 
app/worker.1:  Install missing gem executables with `bundle install` 

为什么系统不接受config参数导致worker崩溃?

无效uri方案的错误依然存在:

app/web.1:  Completed 500 Internal Server Error in 303ms (ActiveRecord: 0.0ms) 
app/web.1:  ArgumentError (invalid uri scheme ''): 

sidekiq.yml 文件

# Sample configuration file for Sidekiq.
# Options here can still be overridden by cmd line args.
# Place this file at config/sidekiq.yml and Sidekiq will
# pick it up automatically.
---
:verbose: false
:concurrency: 10

# Set timeout to 8 on Heroku, longer if you manage your own systems.

:超时:8

# Sidekiq will run this file through ERB when reading it so you can
# even put in dynamic logic, like a host-specific queue.
# http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/
:queues:
  - critical
  - default
  - low

# you can override concurrency based on environment

生产: :并发:25 分期: :并发:10

【问题讨论】:

    标签: heroku redis sidekiq redistogo


    【解决方案1】:

    TL;DR;如果您在本地使用 Sidekiq / Redis 有问题,请将 redis URI 定义为 SIDEKIQ_REDIS_URL=redis://localhost:6379

    文档说 Sidekiq 将尝试连接到 localhost:6379,这可能是真的,但他们遗漏了一个小细节。 URI方案不是httphttps,而是redis

    在我的配置中,我试图传递我在 .env 文件中设置的具体 SIDEKIQ_REDIS_URL

    Sidekiq.configure_server do |config|
        config.redis = { url: ENV.fetch('SIDEKIQ_REDIS_URL'), size: 12, network_timeout: 5 }
    end
    

    现在,如果您不在 .env 中声明 SIDEKIQ_REDIS_URL,它当然不会起作用。更重要的是,即使你添加了默认的URI,它也会失败:

    SIDEKIQ_REDIS_URL=localhost:6379

    它会抱怨 URI 方案

    好像URI方案不是http或者https,而是redis:

    SIDEKIQ_REDIS_URL=redis://localhost:6379

    【讨论】:

      【解决方案2】:

      通过将 redis.rb 和 sidekiq.rb 中的 redis URL 引用更改为相同的 Redis Cloud ENV,我能够更正我的应用程序(Rails 6,Ruby 2.7.2)中失败的 Heroku 部署和 ArgumentError: invalid uri scheme '' 错误变量。

      堆栈跟踪是:

      remote:        Running: rake assets:precompile
      remote:        rake aborted!
      remote:        ArgumentError: invalid uri scheme ''
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:436:in `_parse_options'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis/client.rb:84:in `initialize'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis.rb:62:in `new'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/redis-4.2.2/lib/redis.rb:62:in `initialize'
      remote:        /tmp/build_961a7a51/config/initializers/redis.rb:4:in `new'
      remote:        /tmp/build_961a7a51/config/initializers/redis.rb:4:in `<top (required)>'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:318:in `load'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:318:in `block in load'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:291:in `load_dependency'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:318:in `load'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:666:in `block in load_config_initializer'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/notifications.rb:182:in `instrument'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:665:in `load_config_initializer'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:625:in `block (2 levels) in <class:Engine>'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:624:in `each'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:624:in `block in <class:Engine>'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:32:in `instance_exec'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:32:in `run'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:61:in `block in run_initializers'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:50:in `each'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:50:in `tsort_each_child'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/initializable.rb:60:in `run_initializers'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/application.rb:363:in `initialize!'
      remote:        /tmp/build_961a7a51/config/environment.rb:5:in `<top (required)>'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:34:in `require'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/zeitwerk-2.4.0/lib/zeitwerk/kernel.rb:34:in `require'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:324:in `block in require'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:291:in `load_dependency'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/activesupport-6.0.3.4/lib/active_support/dependencies.rb:324:in `require'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/application.rb:339:in `require_environment!'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/railties-6.0.3.4/lib/rails/application.rb:523:in `block in run_tasks_blocks'
      remote:        /tmp/build_961a7a51/vendor/bundle/ruby/2.7.0/gems/sprockets-rails-3.2.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
      remote:        Tasks: TOP => environment
      remote:        (See full trace by running task with --trace)
      remote:
      remote:  !
      remote:  !     Precompiling assets failed.
      remote:  !
      remote:  !     Push rejected, failed to compile Ruby app.
      remote:
      remote:  !     Push failed
      

      在我的 Heroku 配置中将所有 redis url 引用更改为 Redis Cloud URL 后,我的应用程序部署成功:

      redis.rb

      if ENV["REDISCLOUD_CRIMSON_URL"]
          $redis = Redis.new(:url => ENV["REDISCLOUD_CRIMSON_URL"])
      end
      

      sidekiq.rb

      require 'sidekiq/web'
          
      if Rails.env.development?
        Sidekiq.configure_server do |config|
          config.redis = { url: 'redis://localhost:6379' }
        end
      end
      
      if Rails.env.production?
          Sidekiq.configure_client do |config|
              config.redis = { url: ENV['REDISCLOUD_CRIMSON_URL'], size: 1, network_timeout: 5 }
          end
      
          Sidekiq.configure_server do |config|
              pool_size = (Sidekiq.options[:concurrency] + 2)
              config.redis = { url: ENV['REDISCLOUD_CRIMSON_URL'], size: pool_size, network_timeout: 5 }
          end
      
          Sidekiq::Extensions.enable_delay!
      end
      

      REDIS_URL 和 REDIS_PROVIDER 环境变量也在 Heroku 设置中设置为 REDISCLOUD_CRIMSON_URL(变量,而不是实际值)。希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 2012-12-31
        • 1970-01-01
        • 1970-01-01
        • 2013-03-15
        • 2021-02-27
        • 1970-01-01
        • 1970-01-01
        • 2021-04-30
        • 1970-01-01
        相关资源
        最近更新 更多